开发者

Responding to HTML hyperlink clicks in a C# application

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开发者_StackOverflow中文版 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


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. :)=)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜