1 . 实现IKeyboardHandler接口
public class KeyBoardHander : IKeyboardHandler
{
public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{
return false;
}
public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
{
const int VK_F5 = 0x74;
if (windowsKeyCode == VK_F5)
{
browser.Reload(); //此处可以添加想要实现的代码段
}
return false;
}
}
2 . 在定义ChromiumWebBrowser变量时,加入:
browser = new ChromiumWebBrowser(baseUri)
{
KeyboardHandler = new KeyBoardHander(),
Dock = DockStyle.Fill
};
3 .成功