WebBrowser Control - Prevent Right-Click

17,717

Solution 1

You can set the IsWebBrowserContextMenuEnabled equal to false. You will probably also want to set AllowWebBrowserDrop equal to false too so they cant drag a url into the app and have it load.

        webBrowser1.IsWebBrowserContextMenuEnabled = false;
        webBrowser1.AllowWebBrowserDrop = false;

Solution 2

for any case, winform or wpf:

     private void WebBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            ((WebBrowser)sender).InvokeScript("eval", "$(document).contextmenu(function() {    return false;        });");
}

Solution 3

For WPF ===>

wbBrowser.ContextMenu.IsEnabled = false;

Solution 4

Set the IsWebBrowserContextMenuEnabled property to false.

Share:
17,717
Randy Minder
Author by

Randy Minder

Azure Data Architect / Business Intelligence / Tabular Modeling / Power BI Significant experience with data architecture (database architecture, data warehouses, data marts), SSIS and Azure Data Factory, Business Intelligence with Power BI. Check out my new course on Udemy titled "The DAX Workshop Part 1". The best way to learn DAX is by working through real-world scenarios. The course is filled with exercises (45) to help you learn how to use DAX. Our careers and hobbies are fun and important. But each of us has a soul which will live forever, after our bodies die. Do you know where you'll spend eternity? Jesus Christ said there is only one way to heaven, and it is through Him. You won't get a second chance after you die.

Updated on June 05, 2022

Comments

  • Randy Minder
    Randy Minder almost 2 years

    In my application, I have a form that contains a browser control in which I display an SSRS report. I would like to prevent the user from right-clicking in the browser control and being shown the popup menu. Ideally I'd like the right-click to do nothing. Is there a way I can accomplish this?

  • user1703401
    user1703401 over 13 years
    Works for the Winforms WebBrowser, not the WPF version.
  • Kaganar
    Kaganar almost 11 years
    The WPF version seems to be chiefly underfeatured. I personally end up using Forms' WebBrowser through a WindowsFormsHost control almost every time.
  • KeithS
    KeithS over 8 years
    @Kaganar Only problem with that approach is you're limited to something like IE 5/6-level capabilities for the HTML renderer, unless you set up registry entities to tell IE to use a later version like 10/11 when your app plug into ieframe.dll.
  • Miro Hudak
    Miro Hudak almost 7 years
    This is sort of the best answer, as the most elegant one (stackoverflow.com/a/21699086/592212) has problems (at least I've experienced crashes), when WebBrowser (WPF) was included in custom control. Requires jQuery thought.
  • NitinSingh
    NitinSingh almost 7 years
    works perfectly, without requiring any changes to either the loaded page or application's own design or registry :)
  • Alexandru Dicu
    Alexandru Dicu almost 3 years
    This works only if you assign first a ContextMenu, otherwise it is null by default. The question is about preventing context menu from the displayed web page, not this WPF context menu.