Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Loading
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Appendix B: Graphics, Animation, Drag and Drop
Last change: February 13 2016 18:47:46.
<<PreviousNext>>

B.3. Drag and Drop

Drag and drop provides an interesting and easy way for the user to specify operations that can be too complex to express by some other means. A typical drag-and-drop operation involves dragging an icon to another icon at another location to initiate certain activities. For example, a file can be dragged into a trashcan to delete the file. Typically, in this type of operation, three icons are involved. In the case of dumping a file, one icon will represent the file (the source), another will represent an empty trashcan (the target; before the file is dragged), and the other will represent the trashcan containing the dumped file (after the file is dropped). Only one of the two trashcans will be visible at a given time.
Before a drag and drop operation can be performed, the target control’s AllowDrop property must be set to True (False is the default). Each drag and drop involves three steps:

  1. Set up what is to be dragged. This is done in the source control using the DoDragDrop method, typically in the control’s MouseDown event, which occurs when the user presses the mouse on the source control.
  2. When the drag enters the target control, examine the data type and decide what type of drag-drop effect will be allowed. This is done in the target control’s DragEnter event.
  3. Accept the data or perform the desired operation in the target control’s DragDrop event, which occurs when the user drops the object on the target control by releasing the mouse.
Tip
When testing your drag and drop code, if nothing seems to be active, check the AllowDrop property of your target control first. Make sure your code sets the property to True or it is set to True if it is accessible in the Properties window.

The following two examples illustrate some of the basics of the drag and drop operation.

Last change: February 13 2016 18:47:46.
  1. The Flying Butterfly
  2. Rotating Light Colors
  3. The Rolling Wheel
  • B.3. Drag and Drop
    1. Keeping a Disk in the Holder: An Example
    2. Dragging Texts Among Controls
    3. <<PreviousNext>>