views:

948

answers:

3

I need to capture drag and Drop Events of WebBrowser Control in WinForm C#. Is there any way ?

A: 

Does the standard way of doing drag and drop not work?

http://www.codeproject.com/KB/cs/dragdrop.aspx

Mike Hall
A: 

WebBrowser Customization You can also look into IDocHostUIHandler::GetDropTarget if you want to control what the WebBrowser Control does during drag-and-drop operations.

The easiest way to hook up an implementation of IDocHostUIHandler is to hook up the ICustomDoc interface and all its SetUIHandler method (see http://www.codeproject.com/csharp/advhost.asp). This method has memory leak though. Another method is to skip Windows Form's webbrowser class and use the ActiveX host support directly.

Sheng Jiang 蒋晟
A: 

My Workarond:

use a boolean member variable to detect if you call navigate from inside code or navigating is called from ouside code. Implement the "Navigating" (BeforeNavigating) event and check if it was a call from outside.

Example:

call navigate from inside:

    private void NavigateLocal(string htmlFileName)
    {
        this.localNavigate = true;
        this.webBrowser.Navigate(htmlFileName);
    }

event method:

    private void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
    {
        if (this.localNavigate)//inside call
        {
            this.localNavigate = false;
        }
        else //call from outside
        {

            this.DoDragDrop(e.Url.ToString());
        }
    }
Peter Parker