gpt4 book ai didi

c# - WinForms WebBrowser 阻止 ProcessCmdKey

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:15 25 4
gpt4 key购买 nike

我有一个简单的 Windows 窗体 应用程序,它只不过是一个包含 WebBrowserForm

我正在覆盖 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;
}

最佳答案

您是否尝试过覆盖 WebBroswer 的 ProcessCmdKey...我依稀记得浏览器对冒泡事件做了一些奇怪的事情...与安全有关。是的,它在这里:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.processcmdkey.aspx说:

This method is called during message preprocessing to handle command keys. Command keys are keys that always take precedence over regular input keys. Examples of command keys include accelerators and menu shortcuts. The method must return true to indicate that it has processed the command key, or false to indicate that the key is not a command key. This method is only called when the control is hosted in a Windows Forms application or as an ActiveX control.

The ProcessCmdKey method first determines whether the control has a ContextMenu, and if so, enables the ContextMenu to process the command key. If the command key is not a menu shortcut and the control has a parent, the key is passed to the parent's ProcessCmdKey method. The net effect is that command keys are "bubbled" up the control hierarchy. In addition to the key the user pressed, the key data also indicates which, if any, modifier keys were pressed at the same time as the key. Modifier keys include the SHIFT, CTRL, and ALT keys.

我认为它不会让您在表单级别拦截浏览器键...我认为事件被 WebBrowser 控件吃掉了。

干杯。基思。


编辑:

http://msdn.microsoft.com/en-us/library/system.windows.forms.keys.aspx说:

KeyCode The bitmask to extract a key code from a key value. Modifiers The bitmask to extract modifiers from a key value.

示例包含以下行:

if(e.KeyCode != Keys.Back)

if (Control.ModifierKeys == Keys.Shift) {

所以我想您需要将该 key 旋转成它的组成部分。

关于c# - WinForms WebBrowser 阻止 ProcessCmdKey,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5867662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com