C #. net drag to get the file path
Author attilax, email: 1466519819@qq.com
Idea: Use the dragenter event to obtain the "information" of the dragged window (several files, some text, and so on ),
Parse "information" in the dragdrop event.
The allowdrop attribute of the form must be set to true;
The dragenter event must exist. (If you write a dragdrop event separately, the dragenter event will not be dragged)
Private void form1_dragenter (Object sender, drageventargs E)
{
If (E. Data. getdatapresent (dataformats. filedrop ))
E. effect = dragdropeffects. Link; // importantCode: Indicates data of the link type, such as the file path.
Else E. effect = dragdropeffects. None;
}
Private void form1_dragdrop (Object sender, drageventargs E)
{
String Path = (system. array) E. Data. getdata (dataformats. filedrop). getvalue (0). tostring ();
MessageBox. Show (PATH );
}
Refer:
Winform's mouse drag function (C #)
C # drag-and-drop operation-log of fumingkui @ 126-wangyi blog .htm
Winform(cform _ .nettutorial network-simple and professional .nettechnical website .htm