In computer graphical user interface drag & drop is the action of clicking on an object (virtual object on the screen) and dragging itto different location (on screen) as required.
The basic sequence involved in drag & drop is
Press and hold down the button on the mouse or the other pointing device to “grab” the object.
Drag” the object/cursor/pointing device to the desired location.
“Drop”the object by releasing the button.
A simple drag & drop sequence is given below.
Fig1 contains 2 columns: first column contains animal names and second column contains small boxes where relevant images are dropped.
Fig 1: Images before being dragged to the target
Drag and drop the relevant images
Fig2. Images after being dragged to the target
1.2. How Drag and Drop works
Drag and drop is actually the same as cutting and pasting (or copying and pasting) using the mouse instead of keyboard. In both cases you have
source (where you are cutting or copying from) and a target (where you are pasting to). During either operation, a copy of the data is
maintained in memory. Cut and paste uses clipboard; drag and drop uses a data object, which is in essence private clipboard.
1.3. Properties and methods of Drag & drop
Here is the sequence of events in drag and drop operation:
1. Dragging is initiated by calling DoDragDrop method for source control.
The DoDragDrop method takes 2 parameters
Data, specifying the data to pass
Allowed effects, specifying which operations (copying and/or moving) are allowed
2. A new data object is automatically created.
This in turn raises GiveFeedbackevent. In most cases you do not need to worry about Givefeedback event,but if you wanted to display a custom mouse pointer during the
drag, this is where you would add your code.
Any control with its AllowDropproperty is set to true is potential drop target. AllowDrop property can be set at design time or programmatically at Form Load
As the mouse passes over each control, the DragEnterevent fro that control is raised. GetDatPresentmethod is used to make sure that format of data is appropriate to the
target control and Effect property is used to display the appropriate mouse pointer.
If the user releases the mouse button over a valid drop target, the DragDrop event is raised. Code in the DragDrop event handler extracts
the data from the DataObjectobject and displays it in the target control.
1.4. System Requirement
The example code given in the tutorial runs on any Windows computer running windows7, XP, vista. Project is done in Visual Basic. Net. VB
programmers primarily intend the tutorial for use, and you may be requiring VB.net software installed on your computer to run the program.