简体   繁体   English

如何在Windows 7上进行拖放操作

[英]How to get Drag and Drop to work on Windows 7

I have written a small C# form application that I will use to view some binary files data. 我已经编写了一个小的C#表单应用程序,将用于查看一些二进制文件数据。 I would like to be able to drag and drop files from windows explorer into the application and load them accordingly. 我希望能够将文件从Windows资源管理器拖放到应用程序中并相应地加载它们。 I know there are several related questions on SO about D&D, and I have followed their suggestions about running my app as a normal user / administrator, but I cannot ever make the event for drag and drop fire. 我知道关于D&D的问题与SO有关,因此我遵循了他们关于以普通用户/管理员身份运行我的应用程序的建议,但是我从来没有为拖放事件做过准备。

Here is where I set the allow drop bit & add the event handler to the control (in InitializeComponent()): 在这里设置允许丢弃位并将事件处理程序添加到控件中(在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);

I can set a breakpoint in this.dataGridView1_DragDrop, but it simply never fires. 我可以在this.dataGridView1_DragDrop中设置一个断点,但是它永远不会触发。 Ontop of that, the mouse icon is invariably a circle with a score through it when ever I am dragging a file over my application. 最重要的是,当我在应用程序上拖动文件时,鼠标图标始终是带有分数的圆圈。 I have also tried to add the event handler for drag drop to my form, and pointed it to the same event handler method as my data grid view (and set the AllowDrop bit on the form). 我还尝试过将拖放事件处理程序添加到表单中,并将其指向与数据网格视图相同的事件处理程序方法(并在表单上设置AllowDrop位)。 This to results in identicle behavior. 这导致相同的行为。 What am I missing? 我想念什么?

您必须在http://msdn.microsoft.com/zh-cn/library/aa984430(v=vs.71).aspx中指定的“ DragEnter”事件上设置e.Effect属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM