0

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

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

previously I used the code from the above post to disable the context menu in CefSharp. with the newest update, CefSharp.IContextMenuHandler no longer exists

how can i restore this functionality?

enter image description here

Julien
  • 212
  • 1
  • 18
  • 53
  • What is the exception you are seeing? IContextMenuHandler still exists, in fact the interface hasn't changed in over three years. https://github.com/cefsharp/CefSharp/commits/bef5dd37c4617714729042855120724279501f80/CefSharp/Handler/IContextMenuHandler.cs – amaitland Nov 05 '21 at 19:08
  • added a screenshot of the errors i am getting. basically it seems the references to anything CefSharp got lost somehow. i'm guessing now this is somehow related to my project? all i did was update my nuget packages. – Julien Nov 05 '21 at 19:11
  • What version were you using? What version are you trying to upgrade to? Check the build output rather than relying on the error list. https://github.com/cefsharp/CefSharp.MinimalExample van be used for testing purposes. – amaitland Nov 05 '21 at 19:15
  • went from v94.4.110 to v95.7.141. the build output shows all the same errors `CustomMenuHandler.cs(13,47,13,66): error CS0234: The type or namespace name 'IContextMenuHandler' does not exist in the namespace 'CefSharp' (are you missing an assembly reference?)` – Julien Nov 05 '21 at 19:16
  • the cefsharp minimal example relies on .net framework 4.5.2 which i do not have installed. i tried installing both the runtime and developer pack from the ms page, and it still doesnt work. my project is targetting .net 6.0 – Julien Nov 05 '21 at 19:29
  • i downgraded my nuget package to v94.4.110 and everything works again – Julien Nov 05 '21 at 19:34
  • Which Nuget package are you using? – amaitland Nov 05 '21 at 21:06
  • Install-Package CefSharp.WPF – Julien Nov 06 '21 at 01:47
  • I'm surprised Nuget allowed you to upgrade. That's actually the .Net 4.5.2 package, the hacks that made it work with .Net Core and .Net 5.0+ have been removed. See https://github.com/cefsharp/CefSharp/issues/3444 for options. – amaitland Nov 06 '21 at 08:46
  • thanks much. i switched packages and its all working. – Julien Nov 06 '21 at 15:14

0 Answers0