Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Implementing Drag-and-Drop in Visual Basic 6 : Page 2

The cross-program similarities in Windows operating systems' user interface commands make life a lot easier. Drag-and-drop is one such interface, which can be a significant part of a user interface for those who are happier using the mouse rather than the keyboard. Implementing a traditional drag-and-drop interface is a simple task in Visual Basic 6. This article shows you how to do it.


advertisement
Controls have two properties that are related to drag-and-drop:
  • DragMode. Set to vbManual (value = 0, the default) for manual drag-and-drop, which requires use of the Drag method to initiate a drag-and-drop operation. The control can act as a drag-and-drop source only if you put the required code in the MouseDown event procedure to begin the operation. Set to vbAutomatic (value = 1) to have drag-and-drop initiated automatically when the user depresses the mouse on the control.
  • DragIcon. Specifies the mouse pointer that is displayed while the control is being dragged. The default setting displays an arrow with a rectangle. For a custom mouse icon, set this property at design-time to a .ICO or .CUR file, or at run-time use the LoadPicture function to load an .ICO file.

Executing the Drag method on the source control is required only when the its DragMode property is set to vbManual. The syntax for this method is:

object.Drag action



Set action to vbBeginDrag (value = 1) to initiate a drag operation. This will usually be done in the source control's MouseDown event procedure. You can also call the Drag method with action set to vbCancel or vbEndDrag (values 0 and 2 respectively) to cancel an ongoing drag-and-drop operation or to end a drag-and-drop operation.

Controls have two events that are related to drag-and-drop. DragOver is used to detect when an object is dragged over a control, and DragDrop is used to detect when an object is dropped on a control:

target_DragOver(source As Control, x As Single, y As Single, State As Integer) target_DragDrop(source As Control, x As Single, y As Single)

Target identifies the target object (the one being dragged over or dropped on). It can be a form, an MDI form, or a control. If the target is a control that is part of a control array, these event procedures will have an additional argument that specifies the Index property of the control within the control array.

Source identifies the source control (where the drag-drop operation began).

X and y give the horizontal and vertical position of the mouse pointer with respect to object. These values are always expressed according to the object's coordinate system.

State specifies the relationship between the mouse pointer and the target, as follows:

  • A value of 0 indicates the pointer just entered the target.
  • A value of 1 indicates the pointer is leaving the target.
  • A value of 2 indicates that the pointer is moving within the target.


Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date