Browse DevX
Sign up for e-mail newsletters from DevX


Enable Your Windows Forms Applications to Drag-and-Drop Data Objects : Page 2

This article demonstrates how to import files from the Windows shell and how to enhance some UI controls to make them accept input via drag-and-drop. Notable examples are the TextBox and the PictureBox controls.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Enabling Drag-and-Drop in Forms and Controls
All .NET components allowed in a Windows form have a Boolean property named AllowDrop, which is set to False by default. Turning that value to true is the first and key step to enabling drag-and-drop in a form or a control.

Some drag-and-drop functionality is built into the Control class, which implements very basic functionality required by classes that display information to the user. The Control class handles user input through the keyboard and mouse. Drag-and-drop results from a combined use of the mouse and keyboard. It is worth noting that in the .NET Framework, the Form class—the base class for all Windows form windows—inherits the Control class. This means that the set of drag-and-drop features is common to all forms and controls.

Accomplishing drag-and-drop operations is done handling a series of events and setting a few properties, most notably the aforementioned AllowDrop property. Table 1 lists the key members involved in all drag-and-drop operations.

Table 1: These are the properties, methods, and events to build drag-and-drop support in Windows Forms applications.




Boolean property, indicating whether the control can accept data that the user drags onto it. False by default.


Method used to start a drag-and-drop operation.


Event that occurs when a drag-and-drop operation is completed.


Event that occurs when an object is dragged into the control's bounds.


Event that occurs when an object is dragged out of the control's bounds.


Event that occurs when an object is dragged over the control's bounds.


Event that occurs when a drag-and-drop operation is started. The event allows the source of a drag event to modify the appearance of the mouse pointer in order to give the user visual feedback during a drag-and-drop operation.


Event that occurs during a drag-and-drop operation and allows the drag source to determine whether the drag-and-drop operation should be canceled.

The AllowDrop property is useful if you want the form or control to accept data from external applications or controls. A form or control that only exports data through drag-and-drop doesn't need to set the value to True.

Comment and Contribute






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



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