winform嵌入chrome浏览器(ChromiumWebBrowser),并使用F12控制台来Debug调试,F5刷新

private void Form1_Load(object sender, EventArgs e)
{
ChromiumWebBrowser b = new ChromiumWebBrowser("http://localhost:57531/views/Map/scene.html");
this.Controls.Add(b);
b.Dock = DockStyle.Fill;
b.KeyboardHandler = new CEFKeyBoardHander();
}

  

public class CEFKeyBoardHander : IKeyboardHandler
{//https://bbs.csdn.net/topics/392375553
public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{
if (type == KeyType.KeyUp && Enum.IsDefined(typeof(Keys), windowsKeyCode))
{
var key = (Keys)windowsKeyCode;
switch (key)
{
case Keys.F12:
browser.ShowDevTools();
break;

case Keys.F5:

if (modifiers == CefEventFlags.ControlDown)
{
//MessageBox.Show("ctrl+f5");
browser.Reload(true); //强制忽略缓存

}
else
{
//MessageBox.Show("f5");
browser.Reload();
}
break;


}
}
return false;
}

public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
{
return false;
}
}

  转载 原贴:https://blog.csdn.net/spw55381155/article/details/103127393

posted @ 2020-11-24 15:04  学竹  阅读(3655)  评论(0编辑  收藏  举报