How do I hide the CefSharp.WinForms.ChromiumWebBrowser right click context menu?

前端 未结 5 1461
-上瘾入骨i
-上瘾入骨i 2021-02-07 01:01

I\'m using CefSharp.WinForms.ChromiumWebBrowser v45 in my project. When I right click into the web browser, the default context menu will show up:

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 02:03

    This is the implementation for lazy people like me. It is based on CefSharp v53.0.0

    public class CustomMenuHandler : CefSharp.IContextMenuHandler 
    {
        public void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
        {
            model.Clear();
        }
    
        public bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
    
            return false;
        }
    
        public void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame)
        {
    
        }
    
        public bool RunContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model, IRunContextMenuCallback callback)
        {
            return false;
        }
    }
    

    How to use it

    ChromiumWebBrowser browser = new ChromiumWebBrowser();
    browser.MenuHandler = new CustomMenuHandler();
    

提交回复
热议问题