Windows 7 applications cannot drag and drop files. It turns out that UAC is the cause.

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.