C#.net drag-and-drop implementation to get file path
Author Attilax, Email:[email protected]
Idea: Get the "info" dragged into the window via the DragEnter event (which can be several files, some text, etc.),
The "information" is parsed in the DragDrop event.
The AllowDrop property of the form must be set to true;
and must have a DragEnter event (separate write DragDrop event is not drag-and-drop function)
Private voidForm1_dragenter (Objectsender, DragEventArgs e) { if(E.data.getdatapresent (dataformats.filedrop)) E.effect= Dragdropeffects.link;//Important code: Indicates a link type of data, such as a file path ElseE.effect =DragDropEffects.None; } Private voidForm1_dragdrop (Objectsender, DragEventArgs e) { stringPath = ((System.Array) e.Data.GetData (DataFormats.FileDrop)). GetValue (0). ToString (); MessageBox.Show (path); }View Code
Reference:
WinForm Mouse drag and drop function (C #)
Drag-and-drop operations in C #-[email protected]-blog-netease blogs. htm
WinForm (C #) Drag and drop implementation to get the file path _. NET Tutorial Network--Simple and professional. NET technology Web site. htm
Original link: http://blog.csdn.net/attilax/article/details/8795867
"Go" c#.net drag to get the file path