Click here to Skip to main content
13,259,771 members (55,810 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 31 Dec 2008

Disable the WebBrowser control context menu

, 31 Dec 2008
Rate this:
Please Sign up or sign in to vote.
A simple way to disable the WebBrowser control's context menu.


While developing an application which uses the WebBrowser control that ships with Visual Studio, I realized I didn't want the default context menu to show up when the user right-clicks in the control because I had my own context menu functionality I wanted to implement. Well, you know the routine, search Google and other dev sites to find the answer. There were many solutions, most involving inheriting from some interface in MSHTML and casting that interface to a document, yadda, yadda, yadda.

It turns out that it was much this something new or that no one else knows about, because every other solution was so convoluted?

The code

All you have to do is create a handler on the WebBrowser's Document.ContextMenuShowing event. To do this, place the following code in your form load method on a form with a WebBrowser control:

AddHandler Me.WebBrowser1.Document.ContextMenuShowing, AddressOf WebContextMenuShowing

Place this anywhere in the code:

Private Sub WebContextMenuShowing(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
    'displays your contextmenustrip - you could leave it out to
    ' just disable the browsers context menu
    'suppresses the display of the browsers context menu
    e.ReturnValue = False
End Sub

That's all there is to it!


  • Original submittal - 12/31/2008.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Greg Osborne
United States United States
Visual Basic Developer since version 1.0
Java web developer
Currently developing in vb and c#

You may also be interested in...


Comments and Discussions

QuestionC# equivalnet code available ? Pin
ghiutzu7-Jan-09 0:03
memberghiutzu7-Jan-09 0:03 
AnswerRe: C# equivalnet code available ? Pin
Greg Osborne7-Jan-09 3:29
memberGreg Osborne7-Jan-09 3:29 
GeneralRe: C# equivalnet code available ? Pin
ghiutzu7-Jan-09 3:43
memberghiutzu7-Jan-09 3:43 
AnswerRe: C# equivalnet code available ? Pin
ghiutzu7-Jan-09 22:09
memberghiutzu7-Jan-09 22:09 
Generalsource code Pin
Member 47541155-Jan-09 18:38
memberMember 47541155-Jan-09 18:38 
GeneralRe: source code Pin
Greg Osborne7-Jan-09 3:35
memberGreg Osborne7-Jan-09 3:35 
GeneralThanks to both of you Pin
SteveAbbott31-Dec-08 7:07
memberSteveAbbott31-Dec-08 7:07 
GeneralRe: Thanks to both of you Pin
Greg Osborne7-Jan-09 3:39
memberGreg Osborne7-Jan-09 3:39 
QuestionContextMenuStrip property? Pin
paillave31-Dec-08 5:39
memberpaillave31-Dec-08 5:39 
AnswerRe: ContextMenuStrip property? Pin
Greg Osborne31-Dec-08 5:52
memberGreg Osborne31-Dec-08 5:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 31 Dec 2008
Article Copyright 2008 by Greg Osborne
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid