Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser Control - Prevent Right-Click

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?

like image 637
Randy Minder Avatar asked Dec 20 '10 20:12

Randy Minder


Video Answer


2 Answers

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;
like image 71
Chris Kooken Avatar answered Oct 17 '22 19:10

Chris Kooken


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;        });");
}
like image 34
Andro Lomtadze Avatar answered Oct 17 '22 21:10

Andro Lomtadze