CefSharp屏蔽右键菜单
实现接口:
internal class MenuHandler : CefSharp.IContextMenuHandler
{
public bool OnContextMenuCommand(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.CefMenuCommand commandId, CefSharp.CefEventFlags eventFlags)
{
System.Console.WriteLine(@"OnContextMenuCommand");
return false;
}
public void OnContextMenuDismissed(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame)
{
System.Console.WriteLine(@"OnContextMenuDismissed");
}
public bool RunContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model, CefSharp.IRunContextMenuCallback callback)
{
System.Console.WriteLine(@"RunContextMenu");
return false;
}
public void OnBeforeContextMenu(CefSharp.IWebBrowser browserControl, CefSharp.IBrowser browser, CefSharp.IFrame frame, CefSharp.IContextMenuParams parameters, CefSharp.IMenuModel model)
{
System.Console.WriteLine(@"OnBeforeContextMenu");
model.Clear();
}
}
调用:
_chromiumWebBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
_chromiumWebBrowser.MenuHandler = new MenuHandler();
之后运行,会发现已经屏蔽鼠标右键。