如何取消或处置 WebBrowser 元素的当前导航

发布于 2024-11-18 01:03:09 字数 269 浏览 3 评论 0原文

我正在开发一个 C#、.NET Framework 4.0 应用程序。它按顺序访问一些页面。有时我必须移至下一页而不等待上一页完成工作。如何取消 WebBrowser 元素之前的导航过程?

WebBrowser 元素使用 Internet Explorer。谢谢。

这就是我的导航方式

webBrowser1.Navigate("http://www.mywebsite.com/");

I am developing a C#, .NET Framework 4.0 application. It visits some pages with an order. Sometimes I have to move to the next page without waiting for the previous one to finish the job. How can I cancel the previous navigation process of the WebBrowser element?

WebBrowser element uses Internet Explorer. Thank you.

This is how I navigate

webBrowser1.Navigate("http://www.mywebsite.com/");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤千羽 2024-11-25 01:03:09

有两种直接方法可以做到这一点。首先,您可以简单地在代码中的某个位置调用 WebBrowser 的 Stop 方法。但是,如果您正在寻找一些更精细的控制,您可以连接到 WebBrowser 的 导航事件,并执行如下操作:

private void OnWebBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e) {
    if (somecondition) {
        e.Cancel = true; // Cancels navigation
    }
}

There's two immediate ways to do this. First, you could simply make a call somewhere in your code to the WebBrowser's Stop method. However, if you are looking for some more fine tuned control, you could wireup to the WebBrowser's Navigating event, and do something like this:

private void OnWebBrowserNavigating(object sender, WebBrowserNavigatingEventArgs e) {
    if (somecondition) {
        e.Cancel = true; // Cancels navigation
    }
}
独木成林 2024-11-25 01:03:09

WebBrowser1.Stop()
我记得有这样的东西。它取消当前的导航。

WebBrowser1.Stop()
I remember there being something like this. It cancels the current navigation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文