【发布时间】:2014-10-14 13:41:04
【问题描述】:
我编写了一个小型 C# 表单应用程序,我将使用它来查看一些二进制文件数据。我希望能够将文件从 Windows 资源管理器拖放到应用程序中并相应地加载它们。我知道关于 D&D 有几个关于 SO 的相关问题,并且我已经按照他们关于以普通用户/管理员身份运行我的应用程序的建议进行了操作,但我永远无法让拖放事件发生。
这是我设置允许放置位并将事件处理程序添加到控件的位置(在 InitializeComponent() 中):
this.dataGridView1.AllowDrop = true;
this.dataGridView1.AllowUserToOrderColumns = true;
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(12, 33);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(916, 119);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.DragDrop += new System.Windows.Forms.DragEventHandler(this.dataGridView1_DragDrop);
我可以在 this.dataGridView1_DragDrop 中设置断点,但它根本不会触发。最重要的是,当我在我的应用程序上拖动文件时,鼠标图标总是一个带有分数的圆圈。我还尝试将拖放的事件处理程序添加到我的表单中,并将其指向与我的数据网格视图相同的事件处理程序方法(并在表单上设置 AllowDrop 位)。这会导致相同的行为。我错过了什么?
【问题讨论】:
标签: c# winforms drag-and-drop explorer