[英]How to intercept refresh in Windows Forms WebBrowser control?
I'm using the Windows Forms WebBrowser
control to display a generated report by setting DocumentText
. 我正在使用Windows Forms
WebBrowser
控件通过设置DocumentText
显示生成的报告。 Is there a way I can either prevent the user selecting "refresh" in the right-click menu, or intercept the refresh so that I can regenerate my report? 有什么方法可以阻止用户在右键单击菜单中选择“刷新”,或者拦截刷新以重新生成报告? At the moment the refresh method reloads "about:blank", discarding my report.
目前,刷新方法重新加载“ about:blank”,从而放弃了我的报告。
Browser.AllowNavigation = true;
Browser.DocumentText = "<head></head><body><h1>Test</h1></body>";
So far it seems that refresh does not cause a Navigating
event, and I don't get a DocumentCompleted
event, even though the control does replace the HTML content. 到目前为止,即使控件确实替换了HTML内容,刷新似乎也不会导致
Navigating
事件,并且我也没有得到DocumentCompleted
事件。 I've tried both settings of AllowNavigation
, with no visible difference. 我尝试了
AllowNavigation
两个设置,没有明显的区别。
You can do it using the OnKeyPress
event: 您可以使用
OnKeyPress
事件来做到这一点:
private void KeyPressed(object sender, KeyPressEventArgs e)
{
if(e == Keys.F5)
//do sth;
}
In conjunction with what Simon Mourier said: you could disable the context menu . 结合Simon Mourier所说: 您可以禁用上下文菜单 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.