You must first enable the text box to drag this.txt path. allowdrop = True ;
It was a very simple problem. Mom, I wasted more than an hour. Willingness is the culprit caused by UAC permissions of win7. It's another problem!
Private Void Txtpath_dragenter ( Object Sender, drageventargs E)
{
If (E. Data. getdatapresent (dataformats. filedrop ))
E. effect = dragdropeffects. All;
Else
E. effect = dragdropeffects. None;
}
Private Void Txtpath_dragdrop ( Object Sender, drageventargs E)
{
String [] S = ( String []) E. Data. getdata (dataformats. filedrop, False );
If (S. length> 0 )
{
// Specifies the HTML file type.
If (System. Io. Path. getextension (s [ 0 ]). Tolower () = " . Html " )
{
Txtpath. Text = s [0 ];
}
Else
{
Xtramessagebox. Show ( " Only HTML files can be dragged and dropped. " , " Message " , Messageboxbuttons. OK, messageboxicon. information );
}
}
}
My visual studio2012 is run as an administrator, resulting in ApplicationProgramIt is also run as an administrator. Under the protection of UAC, events such as dragenter, dragover, and dragdrop of the control are not triggered.
Since the emergence of Vista> Windows 7 UAC (User Account Control), there has been a problem with drag-and-drop files:
Any program running as administrator cannot normally accept files dragged into the window!
When our winform application needs to run as an administrator (for example, to access the Windows Registry), we need to change the UAC option"Requireadministrator"(See how to automatically run. net programs as an administrator ?). The EXE icons generated in this way remain unchanged under XP and win2003, but placed under win7, you will find a small shield in the lower right corner of the icon.
How can I solve this drag problem in win7?
Solution: 1. the application does not run as an administrator. Or Visual Studio does not run as an administrator.
Solution 2: Super shameless method: No problem if UAC is set to level 0
If the UAC is set to 0, no problem will occur.
If you have a better method, please leave a message!