实现拖放从Chrome浏览器在我的.NET Windows窗体 [英] Implementing drag-drop from Chrome on my .NET Windows form

查看:304
本文介绍了实现拖放从Chrome浏览器在我的.NET Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谷歌浏览器有一个方便的功能,在那里我可以点击下载链接,并将其拖动到Windows资源管理器窗口,然后放下。滴加后,Chrome浏览器,然后下载文件,它出现在我放弃了它。

Google Chrome has a handy feature where I can click a download link and drag it into a Windows Explorer window, and then drop. After dropping, Chrome then downloads the file and it appears where I dropped it.

我想可以从谷歌浏览器拖放到我的应用程序,但似乎也不是那么简单的。我有一个DataGridView叫gridFiles,下面code:

I would like to be able to drop from Google Chrome into my application, but it seems it isn't so simple. I have a DataGridView called gridFiles, and the following code:

Private Sub gridFiles_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles gridFiles.DragDrop
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        Dim DroppedFiles() As String = e.Data.GetData(DataFormats.FileDrop)
        If Not DroppedFiles Is Nothing Then
            For Each file As String In DroppedFiles
                MsgBox(file)
            Next
        End If
    End If
End Sub

Private Sub gridFiles_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles gridFiles.DragEnter
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then
        e.Effect = DragDropEffects.All
    End If

End Sub

当我文件拖放到它从Windows资源管理器中,一切工作正常,我也得到了被丢弃的每个文件的消息框。但是,当我从铬下降,没有任何反应。这样做的原因是, DroppedFiles 等于没有。看来, e.Data.GetData 不返回任何东西。我已经检查了格式的 e.Data.GetFormats()并返回 FileDrop 文件名 FileNameW 预期与任何文件下降。

When I drop files onto it from Windows Explorer, all works fine and I get a message box for each file that was dropped. However, when I drop from Chrome, nothing happens. The reason for this is that DroppedFiles is equal to Nothing. It seems that e.Data.GetData isn't returning anything. I have checked the formats with e.Data.GetFormats() and it returns FileDrop, FileName, FileNameW as expected with any file drop.

我就是不太清楚正在发生的是Chrome浏览器说,它有一些文件,以便的DragEnter 的功能,但由于还没有下载的文件还没有,的DragDrop 无法做到的,因此Chrome浏览器返回的任何文件。我怀疑,在Windows资源管理器的背景下,Chrome浏览器以某种方式获得该窗口的路径和复制文件本身有后来。

What I am quite sure is happening is that Chrome says it has some files so that the DragEnter functions, but since it hasn't downloaded the file yet, DragDrop cannot be done, so Chrome returns no files. I suspect that in a Windows Explorer context, Chrome somehow gets that window's path and copies the file there itself later.

我怎么能骗过谷歌Chrome浏览器到落入我的应用程序?我看到这个工作通过某种方式给Chrome浏览器它认为它已经降到了文件,我的应用程序会监视文件夹新文件和文件一旦被下载拉他们在临时文件夹。我只需要找到一种方法,Chrome浏览器知道该文件夹。

How can I fool Google Chrome into dropping into my application? I see this working by somehow giving Chrome a temporary folder where it thinks it has dropped the file, and my application would monitor that folder for new files and pull them in once they are downloaded. I just need to find a way for Chrome to "know" that folder.

另外,如果我能得到什么下降的URL,这将是也很不错。然后我可以下载该文件与我的计划。

Alternatively, if I could get the URL of what was dropped, that would be just fine as well. I could then download the file with my program.

任何和所有的建议是多AP preciated。谢谢你。

Any and all advice is much appreciated. Thanks.

编辑:如此看来,与普通的网址,我也得到适当的拖式UniformResourceLocator格式。我看到的行为发生的下载链接在Gmail中。它可能是在其他地方发生,但我不知道。当Gmail附件从Gmail拖到我的应用程序,我得到一个FileDrop。

So it seems that with regular URLs, I do get the proper dragged-in UniformResourceLocator format. The behavior I am seeing occurs with the download links in Gmail. It probably happens elsewhere, but I am not sure. When a gmail attachment is dragged from Gmail into my application, I get a FileDrop.

做一些更多的挖掘,似乎Gmail使用锚标记的 DOWNLOAD_URL 属性。我从来没有听说过这之前。也许这只是他们增加了额外的属性?

Doing some more digging, it seems that Gmail is using the download_url attribute of the anchor tag. I have never heard of this before. Perhaps this is just an extra property they have added?

在任何情况下,因为我的应用程序将主要与电子邮件附件时,我需要一种方法为幻影FileDrop工作,如上所述。我无法使用间谍++。它似乎并没有表现出任何消息时降出现。 (我欢迎对这一问题的任何意见为好。)

In any case, since my application will primarily be used with e-mail attachments, I need a way for the phantom FileDrop to work, as stated above. I am unable to use Spy++. It doesn't seem to show any messages when drops occur. (I welcome any advice on that problem as well.)

编辑#2:以下是Gmail上如何利用拖/放的文件的详细信息:<一href="http://www.thecssninja.com/javascript/gmail-dragout">http://www.thecssninja.com/javascript/gmail-dragout

Edit #2: Here is more information on how Gmail utilizes drag/drop for files: http://www.thecssninja.com/javascript/gmail-dragout

推荐答案

我已经将头发公里出我的头我就奇怪的拖放行为。间谍++所提到的sixlettervariables可能是一个不错的主意。另一个办法是看一看的讨论从我的Q单/正如在这里SO:

I've pulled kilometers of hair out of my head myself regarding weird drag-drop behaviour. Spy++ as mentioned by sixlettervariables might be a good idea. Another would be to take a look at the discussion from one of my Q/As here at SO:

<一个href="http://stackoverflow.com/questions/1201812/drag-and-drop-between-instances-of-the-same-windows-forms-application">Drag和相同的Windows实例之间拖放窗体应用程序

从我自己的经验,我似乎记得从浏览器拖/放是一个安全问题,因此不同的处理。希望这有助于。

From my own experience I seem to remember that drag/drop from a browser is a security issue and thus handled differently. Hope this helps.

编辑:

这也许回答你的问题:

http://www.vbforums.com/showthread.php?t=529211

这篇关于实现拖放从Chrome浏览器在我的.NET Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆