发布:2023/12/7 15:48:44作者:大数据 来源:大数据 浏览次数:843
github:https://github.com/cefsharp/CefSharp/
chromiumWebBrowser1.ShowDevToolsDocked(panel2);
在调用DevTools显示到pannel2时,当窗体大小改变,而控件不会随着窗体大小改变。
解决办法如下:
在浏览器控件中加入生命周期处理程序LifeSpanHandler ,就可以随着窗体大小显示了。
1 2 3 4 5 6 7 8 9 10 11 |
chromiumWebBrowser1.LifeSpanHandler = LifeSpanHandler.Create().OnBeforePopupCreated((chromiumWebBrowser, b, frame, targetUrl, targetFrameName, targetDisposition, userGesture, browserSettings) => { //Can cancel opening popup based on Url if required. //if (targetUrl?.StartsWith("/cancelme.html") == true) //{ // return PopupCreation.Cancel; //} return PopupCreation.Continue; }).Build(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
string url = "www.baidu.com"; chromiumWebBrowser1.Load(url); chromiumWebBrowser1.KeyboardHandler = new CEFKeyBoardHander(); chromiumWebBrowser1.LifeSpanHandler = LifeSpanHandler.Create().OnBeforePopupCreated((chromiumWebBrowser, b, frame, targetUrl, targetFrameName, targetDisposition, userGesture, browserSettings) => { //Can cancel opening popup based on Url if required. //if (targetUrl?.StartsWith("/cancelme.html") == true) //{ // return PopupCreation.Cancel; //} return PopupCreation.Continue; }).Build(); |
F12或F5按键处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
using CefSharp; using CefSharp.WinForms; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp2 { public class CEFKeyBoardHander : IKeyboardHandler { public bool OnKeyEvent(IWebBrowser chromiumWebBrowser, 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: chromiumWebBrowser.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; // throw new NotImplementedException(); } public bool OnPreKeyEvent(IWebBrowser chromiumWebBrowser, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { return false; //throw new NotImplementedException(); } } } |
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4