The new "Cefsharp" disables the right-click menu 43.00+

Source: Internet
Author: User

Disabling the right-click menu is actually very easy. The main is to implement an interface Imenuhandler, this interface has a Onbeforecontextmenu method, we are here to return a false, the right-click menu disappears.

ClassMenuhandler:imenuhandler    {public        bool Onbeforecontextmenu (Iwebbrowser Browser, Icontextmenuparams parameters)        {            return false;        }    } 

It is OK to assign this instance of the image to the Menuhandler property of the Chromiumwebbrowser object.

New Menuhandler ();

The above method applies to older versions of Cefsharp

43.00 start,Imenuhandler has been renamed, directly copy the above code does not exist

Asked the master, his own thinking of the original changed into a Icontextmenuhandler

And this interface below already have a few control menu method, because I get started C # is not deep, only according to the VS prompt, said interface needs to be rewritten,

The method is rewritten as prompted, but the default is throw new NotImplementedException ();

Obviously this is not possible, these three methods from the literal understanding, Control menu appearance should be Onbeforecontextmenu, there are 2, one is bool, one does not know

Look carefully, the second does not need to return the value, there is a imenumodel model, inadvertently seen on the Internet master directly call CEF with Cefsharp a method model. Clear ();

Write down the following code, and also ask the master to see the following correction

Internal class Menuhandler:icontextmenuhandler
{
public bool Onbeforecontextmenu (iwebbrowser browser,ibrowser ibrower,iframe iframe,icontextmenuparams Icontextmenuparams,imenumodel Imenumodel)
{
return false;
}

public bool Oncontextmenucommand (iwebbrowser BrowserControl, Ibrowser browser, IFrame frame, icontextmenuparams Parameters, Cefmenucommand commandId, Cefeventflags eventflags)
{
return false;
throw new NotImplementedException ();
}

public void oncontextmenudismissed (Iwebbrowser browsercontrol, Ibrowser Browser, IFrame frame)
{
throw new NotImplementedException ();
}

void Icontextmenuhandler.onbeforecontextmenu (Iwebbrowser browsercontrol, Ibrowser browser, IFrame frame, Icontextmenuparams parameters, Imenumodel model)
{
Model. Clear ();
}
}

The new "Cefsharp" disables the right-click menu 43.00+

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.