Disabling right click in WebBrowser control 
Author Message
 Disabling right click in WebBrowser control
Is disabling the right click menu in WebBrowser control posible via the
WebBrowser properties/events, without code modifications to the pages? If
so, any examples I can see? I've found a VB6 project that does exactly this,
( http://www.*-*-*.com/ ) but I can't get it to
convert to a .NET studio project, with errors popping up on conversion :(

James Connor



Wed, 23 Mar 2005 02:17:40 GMT  
 Disabling right click in WebBrowser control
Hello James,

To disable the right click of a WebBrowser control, you may handle the
MouseDown event of HTML document. In the handler, cancel the bubble if the
right button is clicked. Here is a sample code of it:

private void Form1_Load(object sender, System.EventArgs e)
{
        Object url = "www.microsoft.com";
        Object nul = null;
        axWebBrowser1.Navigate2(ref url, ref nul, ref nul, ref nul, ref nul);

Quote:
}

private void button1_Click(object sender, System.EventArgs e)
{
        IHTMLDocument2 doc = (IHTMLDocument2)axWebBrowser1.Document;
        HTMLDocumentEvents2_Event htmlEvents = (HTMLDocumentEvents2_Event)doc;
        htmlEvents.onmousedown += new
HTMLDocumentEvents2_onmousedownEventHandler(OnMouseDown);

Quote:
}

public static void OnMouseDown(IHTMLEventObj e)
{
        if(e.button == 2) //Right Click
                e.cancelBubble = true;

Quote:
}

I hope this helps you.

Best regards,

Lion Shi [MS]
MCSE, MCSD
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
reserved.
--------------------

    Newsgroups: microsoft.public.dotnet.languages.CSharp
    Subject: Disabling right click in WebBrowser control
    Date: Fri, 4 Oct 2002 19:17:40 +0100
    Organization: Posted via Supernews, http://www.supernews.com

    X-Priority: 3
    X-MSMail-Priority: Normal
    X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
    X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

    Lines: 9
    Path:
cpmsftngxa09!cpmsftngxa08!tkmsftngp01!newsfeed00.sul.t-online.de!t-online.de
!news.stealth.net!news.stealth.net!telocity-west!TELOCITY!sn-xit-03!sn-xit-0
6!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
    Xref: cpmsftngxa09 microsoft.public.dotnet.languages.csharp:97677
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    Is disabling the right click menu in WebBrowser control posible via the
    WebBrowser properties/events, without code modifications to the pages?
If
    so, any examples I can see? I've found a VB6 project that does exactly
this,
    (http://www.vbcity.com/download/HTMLViewerSample.zip) but I can't get
it to
    convert to a .NET studio project, with errors popping up on conversion
:(

    James Connor



Sat, 26 Mar 2005 10:42:07 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Disabling right click menu in Webbrowser

2. WebBrowser control:Trapping right click

3. disable the right click function in ActiveX Browser control

4. removing the right click menu from webbrowser

5. Disable right-mouse click IE-menu in the CWebBrowser class

6. disable webBrowser control to move around

7. disable context menu in WebBrowser Control

8. Disabling Back Command on a WebBrowser Control

9. disable cache in webbrowser control

10. Web Browser Control - Add Border - Remove Right Click Functionality

11. Capture Right-Click in ActiveX Control

12. Controlling Right Click Options.

 

 
Powered by phpBB® Forum Software