![]() |
Desktop Development »
Miscellaneous »
HTML Browser Controls
Beginner
License: The Code Project Open License (CPOL)
Disable the WebBrowser control context menuBy Greg OsborneA simple way to disable the WebBrowser control's context menu. |
VB (VB 9.0), C# 3.0, .NET (.NET 3.5), Visual Studio (VS2008), WinForms, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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 simpler...is this something new or that no one else knows about, because every other solution was so convoluted?
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
Me.WebBrowser1.ContextMenuStrip.Show(Cursor.Position)
'suppresses the display of the browsers context menu
e.ReturnValue = False
End Sub
That's all there is to it!
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 31 Dec 2008 Editor: Smitha Vijayan |
Copyright 2008 by Greg Osborne Everything else Copyright © CodeProject, 1999-2009 Web10 | Advertise on the Code Project |