实现接口:

 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
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();
    }
}

调用:

1
2
_chromiumWebBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
_chromiumWebBrowser.MenuHandler = new MenuHandler();

之后运行,会发现已经屏蔽鼠标右键。