views:

371

answers:

1

Question:

How can I detect and handle clicks on hyperlinks in a Windows.Forms.WebBrowser control in C#?

Background:

My C# application does not carry a centralised help file. Instead, all the pieces that make up the app are allowed to display their own little help topic. This was done because the application is merely a framework, and it's hundreds of little plug-ins that actually make it useful.

Each class can implement an interface which registers it with the help UI. All my help topics are html strings (but I'm not particularly wedded to that), many of which are created programmatically at runtime.

The problem is that these topics are all isolated. I'd very much like to be able to include a "See also" section which will open other help topics. But how can I handle hyperlink-clicks in a Windows.Forms.WebBrowser?

Much obliged, David

+2  A: 

If I understand correctly, you would like to override your hyperlink-clicks with your own Form or UI. Well, if that's the case, you put your code on the OnNavigating event of Web Browser and make e.Cancel = true so that it will not navigate the URL specified by your hyperlink.

some snippet:

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
    {
        e.Cancel = true;
        SeeAlsoFrm seeAlso = new SeeAlso();
        seeAlso.showDialog();
    }

that is based on my understanding. :)=)

junmats
That was a lot simpler than I expected. Thanks!
David Rutten