System.Windows.Forms.WebBrowser.Refresh 显示上一页 [英] System.Windows.Forms.WebBrowser.Refresh showing previous page

查看:19
本文介绍了System.Windows.Forms.WebBrowser.Refresh 显示上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 WinForms 应用程序有一个带有 System.Windows.Forms.WebBrowser 控件的选项卡.有几个控件可以设置 WebBrowser 的 .Url 属性,当表单重新绘制时,它会调用 WebBrowser 的 .Refresh(WebBrowserRefreshOption.Completely) 方法.

My WinForms application has a tab with a System.Windows.Forms.WebBrowser control. There are several controls that set the WebBrowser's .Url property, and when the form repaints it calls the WebBrowser's .Refresh(WebBrowserRefreshOption.Completely) method.

但是,有时会重新绘制表单并且 WebBrowser 内容不会更改.我打破了 .Refresh( ).Url 是前一个 Url.怎么回事?

Occasionally, however, the form gets repainted and the WebBrowser content doesn't change. I break on the .Refresh( ), and the .Url is the previous Url. What's going on?

根据 MSDN:

如果您设置此属性的值,然后立即再次检索它,如果 WebBrowser 控件没有时间加载新文档,则检索到的值可能与设置的值不同.
If you set the value of this property and then immediately retrieve it again, the value retrieved may be different than the value set if the WebBrowser control has not had time to load the new document.

那是不是很特别?为什么 .Refresh( ) 在重绘之前不等待控件有时间加载新文档"?有没有办法强制这种情况发生?

Well isn't that special? Why doesn't .Refresh( ) wait until the control has "had time to load the new document" before it redraws? Is there any way to force this to happen?

推荐答案

除非您正在做一些非常特别的事情,否则强制 WB 重新绘制自身是没有意义的.由于它是自己的控件并有自己的句柄,因此它可以在认为必要时重新绘制自己.由于您强制它在与 ReadyState 完全不同步的时刻重新绘制,因此会得到一个旧"网址.

Unless you're doing something very special, it doesn't make sense to force the WB to repaint itself. Since it is its own control and has its own Handle, it is quite capable of repainting itself whenever it deems necessary. Since you are forcing it to repaint at a moment that's completely out of sync with its ReadyState, getting an "old" url is to be expected.

这篇关于System.Windows.Forms.WebBrowser.Refresh 显示上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆