Catch DragEnter and DragDrop events on webbrowser

南笙酒味 提交于 2019-12-12 11:28:24

问题


I have TreeView, ListView and WebBrowser controls. I use the drag and drop method. With the TreeView and ListView everything works, because they have Dragdrop and DragEnter event. But I did not find them in 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

e.Effect = DragDropEffects.None;

The Drag and DragEnd events is not triggered.

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.
  2. Is there a way to process data as well as Dragdrop and DragEnter for WebBrowser?

回答1:


  1. Changing the cursor here Change webbrowser Cursor. 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#:

    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
    }
    


来源:https://stackoverflow.com/questions/19858128/catch-dragenter-and-dragdrop-events-on-webbrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!