我对此感到困惑。我试图在DataGridView
上执行拖放操作。没有看到任何事件发生,我用一个文本框尝试了一个简单的表单。C#WinForms DragEnter永远不会触发
我想能够从Windows资源管理器中拖动文件或文件夹。
我错过了一些东西,因为这些事件永远不会发生。我没有读到DragEvents, Windows 7 and UIPI,但我仍然无法解决这个问题。
我出来的想法,我欢迎您的建议。
public Form1()
{
InitializeComponent();
this.AllowDrop = true;
textBox1.AllowDrop = true;
textBox1.DragEnter += new DragEventHandler(textBox1_DragEnter);
textBox1.DragDrop += new DragEventHandler(textBox1_DragDrop);
textBox1.DragOver += new DragEventHandler(textBox1_DragOver);
}
void textBox1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
void textBox1_DragDrop(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
void textBox1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
看来,这应该工作。我在WP7 64上进行了全新安装 - 包括所有更新,我没有运行病毒或恶意软件保护,或者任何可以阻止这些事件触发的信息(据我所知)。
您试图从应用程序拖动到另一个应用程序? – 2012-01-08 10:38:41
表单的DragEnter事件处理程序不会触发,您没有订阅该事件。没有明显的原因为什么文本框'事件不会触发。在其上设置一个断点并将文件从Windows资源管理器拖到该框。 – 2012-01-08 11:44:46
@YochaiTimmer我更新了这篇文章,我试图从资源管理器中拖动文件。 – nullable 2012-01-08 21:36:05