nul*_*ble 7 c# drag-and-drop windows-7 winforms
我对此感到困惑.我试图在a上执行拖放操作DataGridView.没有看到任何事件被触发,我尝试了一个带有文本框的简单表单.
我希望能够从Windows资源管理器中拖动文件或文件夹.
我错过了一些东西,因为这些事件从未发生过.我读过关于DragEvents,Windows 7和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;
}
Run Code Online (Sandbox Code Playgroud)
看来这应该有效.我在WP7 64上有一个干净的安装 - 所有更新,我没有运行病毒或恶意软件保护,或任何(据我所知)可能阻止这些事件发生的事情.
小智 32
我遇到过同样的问题.这只是因为我从"以管理员身份运行"会话进行调试.我认为,自VISTA以来,有一种安全措施可以防止丢弃到特权应用程序.
小智 5
我发现当我在 Visual Studio 中以调试模式运行 Forms 应用程序时,它不起作用。只有当我在 VS 之外运行它时,它才能完美运行。据推测,这也与 Windows 7(可能还有更高版本)的安全性有关。