Login | Register   
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

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
ne major advantage of the Windows operating system—and most other operating systems for that matter—is that it provides all programs with a similar user interface. A program's menu, for example, is always displayed across the top of its window, and its commands can be accessed with the mouse or by using the Alt key. Pressing Alt+F4 closes a program, F1 is almost always the Help key, and Ctrl+P usually is the command for printing. These and other cross-program similarities in user interface commands make the user's life a lot easier. Imagine having to learn a new interface and all new commands for each program!

One important aspect of the Windows interface that many developers overlook is drag-and-drop. The ability to carry out program operations using drag-and-drop can be a significant part of a user interface, particularly for those users who are happier using the mouse rather than the keyboard. Implementing drag-and-drop in a Visual Basic 6 program is a relatively simple task. This article covers only traditional drag-and-drop, which permits items to be dragged from one part of a program to another part of the same program. There is a second kind of drag-and-drop that permits items to be dragged from one program to another program, which is not covered here.

The Basics of Drag and Drop
A drag-and-drop operation involves a source and a target. The source can be any Visual Basic control, and the target can be any control or the form itself. The operation has three parts:

  • The operation begins when the user presses the mouse button as the pointer is over a control that has been enabled as a drag-and-drop source.
  • The operation continues as the pointer is moved, with the left mouse button still down, over other controls or the form itself. A control receives notification, via the DragOver event, that it is being "dragged over" and can signal whether the data can be dropped on it by changing the appearance of the mouse pointer.
  • The operation ends when the user releases the mouse button. A control is notified by the DragDrop event that it has been dropped on.
It's important to note that what is being dragged is the source control. It's not being dragged literally—it does not move on the form—but its identity is being dragged. Both the DragOver and DragDrop events inform the target control of the identity of the source control, and code in the event procedure can take action accordingly.


Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap