更新时间:2023-12-06 16:45:40
假定这是一个带有WebBrowser
控件的Windows Forms项目:WebBrowser
会在有焦点的任何时候吃掉击键",即使Form KeyPreview也是如此.设置为"true".
Assuming this is a Windows Forms project with a WebBrowser
control: the WebBrowser
will "eat the keystrokes" anytime it has focus, even if Form KeyPreview is set to 'true'.
使用WebBrowser PreviewKeyDown事件调用按钮单击:
Use the WebBrowser PreviewKeyDown event to call the button click:
private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs event)
{
// Possibly filter here for certain keystrokes?
// Using e.KeyCode, e.KeyData or whatever.
button1.PerformClick();
}