How to open a link in webBrowser control in external browser?

前端 未结 6 1517
轮回少年
轮回少年 2020-12-15 19:39

I have a textBox and a webBrowser control in my Windows Forms application. Whenever a user enters a HTML code in textBox, the webBrowser control shows its compiled form. The

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 19:59

    I would like to add something more to this answer,

    Coz webBrowser1_Navigating method is executed everytime when the content of the webBrowser is changed.

    In your case whenever you set the values to DocumentText this method is called and when there is no url and its default value is about:blank. So we should also check this for otherwise it won't load any content.

        private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (!(e.Url.ToString().Equals("about:blank", StringComparison.InvariantCultureIgnoreCase)))
            {
                System.Diagnostics.Process.Start(e.Url.ToString());
                e.Cancel = true;
            }
        }
    

提交回复
热议问题