Article ID: 306969 - Last Review: May 13, 2007 - Revision: 3.5 How to provide file drag-and-drop functionality in a Visual Basic 2005 or Visual Basic .NET application
This article was previously published under Q306969
For a Microsoft Visual C# .NET version of this article, see 307966
(http://support.microsoft.com/kb/307966/
)
.
On This PageSUMMARY
The step-by-step procedure in this article demonstrates how to provide file drag-and-drop functionality in a Microsoft Visual Basic 2005 or Microsoft Visual Basic .NET application. A ListBox control is used as the destination of the file drag-and-drop procedure. RequirementsThe following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
Steps to build the sampleThe ListBox control provides two drag-and-drop events that you need to handle: DragEnter and DragDrop. The DragEnter event occurs when you drag an object within the bounds of the control and is used to determine whether the object that is being dragged is one that you want to allow to be dropped on the control. You handle this event for cases in which a file or files are dragged to the control. This allows the appropriate icon to be displayed when the object is dragged over the control, depending on the object that is being dragged. The DragDrop event occurs when the object that is being dragged has been released on the control. You handle this event to retrieve the object. The Data object is used to retrieve the data.The Data object's GetData method returns an array of strings that contain the full path names of the files that were dragged to the ListBox control. You can use this file path information to perform whatever operations are needed on the files. For example, you can use classes in the System.IO namespace to open and read the files, move the files, or copy the files to a new location. This sample only adds the full path to the files that are dragged to the ListBox control. To provide file drag-and-drop functionality in a Visual Basic 2005 or Visual Basic .NET application, follow these steps:
REFERENCES
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.dragenter(vs.71).aspx
(http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.dragenter(vs.71).aspx)
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.dragdrop(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.dragdrop(vs.71).aspx) | Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|





















Back to the top