一旦用鼠标拖动文件放到Form上面,鼠标就变成了一个圆圈中间有个斜杠(即代表无法把文件拖进去)
但我确实已经把Form的AllowDrop属性设置为true,
问这个问题的不止我一个,解决方法也都试过(如关闭UAC、如添加DragEnter的方法),均无效。
https://blog.csdn.net/FL1623863129/article/details/77066036?locationNum=6&fps=1
https://blog.csdn.net/aiqinxuancai/article/details/50903564
http://tieba.baidu.com/p/3059784450
https://zhidao.baidu.com/question/515025128.html
实在不知道哪里出了问题。
可在这里下载源文件,很简单的几段代码(从网上抄来的):
https://pan.baidu.com/s/1A6ag0xpB3nmyP4JG2UmvXQ
(另外,该代码中有个按钮和文字框,无视里面的内容就好)
以下有简易的代码可供浏览。但我觉得可能不只是代码本身的问题?
public Form1()
{
InitializeComponent();
this.AllowDrop = true;
}
private void Form1_Load(object sender, EventArgs e)
{
this.AllowDrop = true;
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
//e.Effect = DragDropEffects.Move;
//lb1.Text = "12345";
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link;
else e.Effect = DragDropEffects.None;
}
}