简体   繁体   English

在webbrowser上捕获DragEnter和DragDrop事件

[英]Catch DragEnter and DragDrop events on webbrowser

I have TreeView, ListView and WebBrowser controls. 我有TreeView,ListView和WebBrowser控件。 I use the drag and drop method. 我使用拖放方法。 With the TreeView and ListView everything works, because they have Dragdrop and DragEnter event. 使用TreeView和ListView一切正常,因为它们具有Dragdrop和DragEnter事件。 But I did not find them in WebBrowser. 但我没有在WebBrowser中找到它们。

I try using: 我尝试使用:

webBrowser1.Document.Body.Drag += new HtmlElementEventHandler(WebBrowser_Drag);
webBrowser1.Document.Body.DragOver += new HtmlElementEventHandler(WebBrowser_DragOver);
webBrowser1.Document.Body.DragEnd += new HtmlElementEventHandler(WebBrowser_DragEnd);
webBrowser1.Document.Body.DragLeave += new HtmlElementEventHandler(WebBrowser_DragLeave);

The DragOver and DragLeave events triggered, but it is not possible to change the cursor like 触发了DragOver和DragLeave事件,但是无法更改光标

e.Effect = DragDropEffects.None;

The Drag and DragEnd events is not triggered. 不会触发Drag和DragEnd事件。

I also try: 我也尝试:

webBrowser1.Document.Body.AttachEventHandler("dragdrop", WebBrowser_DragDrop);
webBrowser1.Document.AttachEventHandler("dragdrop", WebBrowser_DragDrop);
webBrowser1.Document.AttachEventHandler("ondrop", WebBrowser_OnDrop);
webBrowser1.Document.Body.AttachEventHandler("ondrop", WebBrowser_OnDrop);

but it does not work well. 但它效果不好。

Now I have some questions: 现在我有一些问题:

  1. How to change the cursor in the event DragOver and DragLeave. 如何在DragOver和DragLeave事件中更改光标。
  2. Is there a way to process data as well as Dragdrop and DragEnter for WebBrowser? 有没有办法处理数据以及WebBrowser的Dragdrop和DragEnter?
  1. Changing the cursor here Change webbrowser Cursor . 在此处更改光标更改webbrowser光标 But among the possible cursors unfortunately no draganddrop cursor. 但遗憾的是游标中没有拖拽光标。
  2. The easiest way to solve my problem that I have found is to use a transparent panel Clearing the graphics of a transparent panel C# : 解决我发现问题的最简单方法是使用透明面板清除透明面板C#的图形

     private void WebBrowser_DragOver(object sender, HtmlElementEventArgs e) { panel.BringToFront(); } private void Panel_DragLeave(object sender, EventArgs e) { panel.SendToBack(); } private void Panel_MouseLeave(object sender, EventArgs e) { panel.SendToBack(); } private void Panel_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Move; } private void Panel_DragDrop(object sender, DragEventArgs e) { //Make dragdrop data processing } 

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

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