WebBrowser在IE中打开链接而不是默认浏览器?(WebBrowser opens link in IE instead of Default Browser?)

编程入门 行业动态 更新时间:2024-10-28 19:19:06
WebBrowser在IE中打开链接而不是默认浏览器?(WebBrowser opens link in IE instead of Default Browser?)

所以我有一个打开一个新窗口的WPF应用程序。 然后在该新窗口中,它创建一个webBrowser对象:

WebBrowser browser = new WebBrowser(); browser.Source = new System.Uri(chatUrl); browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating); this.browserControl.Child = browser;

如您所见,我为NavigatingCancelEventHandler创建了一个钩子。 基于我所看到的,这个处理程序应该拦截在webbrowser中点击的链接。

private void browser_Navigating(object sender, NavigatingCancelEventArgs e) { e.Cancel = true; System.Diagnostics.Process.Start(e.Uri.ToString()); }

所以我进行导航,取消它并使用Process.Start函数在我的默认浏览器中打开它。 问题是,它没有这样做。 它仍然在IE9中打开。 我在StackOverflow上看过其他线程,他们都说要做我正在做的事情。 但我正在做的事情不起作用。 请帮忙。

So I have a WPF application that opens up a new window. Then on that new window, it creates a webBrowser object:

WebBrowser browser = new WebBrowser(); browser.Source = new System.Uri(chatUrl); browser.Navigating += new NavigatingCancelEventHandler(browser_Navigating); this.browserControl.Child = browser;

As you can see, I have created a hook for NavigatingCancelEventHandler. Based on what I've seen, this handler is supposed to intercept links clicked within the webbrowser.

private void browser_Navigating(object sender, NavigatingCancelEventArgs e) { e.Cancel = true; System.Diagnostics.Process.Start(e.Uri.ToString()); }

So I take the navigation, cancel it and use the Process.Start function to open it in my default browser. The problem is, it doesn't do this. It still opens up in IE9. I've seen other threads here on StackOverflow, and they all say to do what I'm doing. But what I'm doing doesn't work. Please help.

最满意答案

您正在为事件处理程序使用不正确的委托类型,您正在指定NavigatingCancelEventArgs但它应该是WebBrowserNavigatingEventHandler。

找到正确方法的最简单方法就是输入

browser.Navigating +=

然后按TAB两次,它将为您生成正确的处理程序。

编辑:嗯,我正在看SWF版本,但我会在WPF的任何一种情况下尝试上述内容。

You're using the incorrect delegate type for your event handler, you're specifying a NavigatingCancelEventArgs but it should be a WebBrowserNavigatingEventHandler.

Easiest way to get the right one is to just type

browser.Navigating +=

And press TAB twice, it'll generate the correct handler for you.

Edit: Hmm, I'm looking at the S.W.F version, but i'd try the above in either case for WPF.

更多推荐

本文发布于:2023-07-16 18:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1132415.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   浏览器   链接   WebBrowser   Browser

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!