Drag and drop is actually the same as copy & paste using the mouse instead of the keyboard. In both cases you have a source control (where you are cutting or copying from) and a target control (where you are pasting to). During either operation, a copy of the data is maintained in memory. Cut and paste uses the Clipboard; drag and drop uses a DataObject object, which is in essence a private clipboard.
VB6 supported several drag and drop types: Standard and OLE drag and drop with manual and automatic modes for both types.
Data is passed by using the source control as a drag and drop parameter. The drag operation sets the source control in drag and drop mode. DragOver and DragDrop event handlers in the target control receive the source control so they can obtain the data to be copied or moved from the source control itself.
Data is passed by using the source control as a drag and drop parameter. The data to be copied or moved is set at the beginning of the drag and drop operation inside the OLEStartDrag event handler or by demand by the OLESetData event handler. The OLEDragOver and OLEDragDrop event handlers received the data in a DataObject parameter.
Drag and Drop in .NET is very similar to VB6 manual OLE drag and drop. The concept and functionality is the same but the names and sequences of events are different.
Handling of the DragOver event is very different in .NET. VB6 provided one handler with the action specified by a state parameter. In .NET the handling is now realized by three different event handlers, one handler for each possible DragOver “states”: drag enter, drag over and drag leave.
Programming of the drag and drop feedback to the user has changed as well. In VB6, the visual notification of allowed drag and drop operations had to be programmed in the DragOver event, where the mouse icon could be changed to another to indicate that the control allows drag and drop operations. The code in the DragDrop event was the one that managed what to do with the data dropped into the control. In .NET, the controls that allow drag and drop events need to have that feature enabled first. The feature is enabled by setting the AllowDrop property of the control to true. Also, the types of allowed drag and drop operations must be specified by setting a DragDropEffect value in the drag over or drag enter event handlers.
.NET now handles automatically the changes in mouse icons during drag and drop operations. If the programmer desires to handle mouse pointer icons manually, the procedure for doing it is somewhat different than in VB6. In VB6’s standard drag and drop, the mouse pointer changes had to be specified in the event handlers of each one of the target controls. In .NET, handling this functionality can be simplified by handling the mouse pointer changes in the GiveFeedback event handler of the source control.
Functionality | Visual Basic 6.0 | .NET |
Start drag method | object.Drag | object.DoDragDrop |
Drag drop event handler | object_DragDrop | object_DragDrop |
Drag Over event handler | object_DragOver |
object_DragEnter object_DragOver object_DragLeave |
Drag Over states | state parameter of DragOver event handler |
object_DragEnter object_DragOver object_DragLeave |
Drag icon property | object.DragIcon in each control’s DragOver event handler |
1. GiveFeedbackEventArgs parameter in drag over event handler (auto) 2. object.Cursor property of target control (custom) |
Functionality | Visual Basic 6.0 | .NET |
Start drag method | object.OLEDrag | object.DoDragDrop |
Start drag event handler | object_OLEStartDrag | N/A (use DoDragDrop method) |
Drag Drop event handler | object_OLEDragDrop | object_DragDrop |
Drag Over event handler | object_OLEDragOver |
object_DragEnter object_DragOver object_DragLeave |
Feedback event handler | object_OLEGiveFeedback | object_GiveFeedback |
Drag complete handler | object_OLECompleteDrag | object_DragDrop (target) |
Set Data event handler | object_OLESetData | N/A ( use DragEventArgs Data.SetData method in DragDrop event handler) |
8834 N Capital of Texas Hwy, Ste 302
Austin, TX 78759
Call us: +1 (425) 609-8458
info@wearegap.com