WinForms WebBrowser 阻止 ProcessCmdKey
我有一个简单的Windows 窗体应用程序,它只不过是一个包含WebBrowser
的Form
。
我正在重写 ProcessCmdKey 方法而且效果很好。但是,虽然 WebBrowser
具有焦点,但仍会调用 ProcessCmdKey
,但它不再获取关键代码。
protected override bool ProcessCmdKey(ref Message msg, Keys keyData){
//When webbrowser has focus, only control or S are found - not both.
if(keyData==(Keys.Control|Keys.S)){
//Do things here.
return true;
}
return false;
}
I've got a simple Windows Forms application that's nothing more than a Form
that contains a WebBrowser
.
I'm overriding the ProcessCmdKey method and it works fine. But, while the WebBrowser
has the focus, ProcessCmdKey
is still called, however, it no longer picks up key codes.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData){
//When webbrowser has focus, only control or S are found - not both.
if(keyData==(Keys.Control|Keys.S)){
//Do things here.
return true;
}
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试覆盖 WebBroswer 的 ProcessCmdKey...我隐约记得浏览器对冒泡事件做了一些奇怪的事情...与安全有关。是的,这里是:
http://msdn .microsoft.com/en-us/library/system.windows.forms.control.processcmdkey.aspx 说:
我不认为它会让您在表单级别拦截浏览器按键...我认为这些事件被 WebBrowser 控件吃掉。
干杯。基思.
编辑:
http:// msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx 说:
该示例包含以下行:
所以我想您需要将该密钥稍微调整到它的组成部分中。
Did you try overriding the WebBroswer's ProcessCmdKey... I vaguely recall the browser does something funky with bubbing-up events... to do with security. Yeah, here it is:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.processcmdkey.aspx Says:
I don't think it'll let you intercept browser keys at the form level... I think the events are eaten by the WebBrowser control.
Cheers. Keith.
EDIT:
http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx says:
and the example contains the lines:
So I guess you need to bit-twiddle that key into it's component parts.
不幸的是,我无法从
ProcessCmdKey
+ Lo/Hi 单词捕获 Ctrl+S 事件。但我可以从
WebBrowser
文档中捕获它们:Unfortunaley I can't catch Ctrl+S event from
ProcessCmdKey
+ Lo/Hi words.But I can catch them from
WebBrowser
document:就我而言,我想处理 F1 键。
使用 Web 浏览器控件的按键预览会有所帮助:
这样做不需要重写 Web 浏览器控件的 ProcessCmdKey 。
但这种方法不适用于 Ctrl+S 。
In my case, I wanted to process the F1 key.
Using the key preview of the webbrowser control helped:
Doing so didn't require overriding
ProcessCmdKey
of the webbrowser control.This approach doesn't work for Ctrl+S though.