The easiest way to do this is to disable the context menu of the
document contained in the WebBrowser control e.g.
WebBrowser1.IsWebBrowserContextMenuEnabled = False
You could do this in the
WebBrowser_Navigated
event (rather than the
Form_Load
event) so that it applies to every page you might navigate to.
If you want to do something else when the User right-clicks in the browser control you actually want to handle the right-click rather than ignore it.
You could do something like this (the name of the function is arbitrary)
Private Sub WebDocument_MouseDown(ByVal sender As System.Object, ByVal e As HtmlElementEventArgs)
If (e.MouseButtonsPressed = MouseButtons.Right) Then
End If
End Sub
And add the handler as
RemoveHandler WebBrowser1.Document.MouseDown, New HtmlElementEventHandler(AddressOf WebDocument_MouseDown)
AddHandler WebBrowser1.Document.MouseDown, New HtmlElementEventHandler(AddressOf WebDocument_MouseDown)
Note that I remove it first (there is no exception thrown if it doesn't exist) to prevent the handler being added multiple times.
Also note that if you have added a URL at design time then you should not add the handler in the Form_Load event as the WebBrowser.Document object will not yet exist (and an exception will be thrown). The WebBrowser_Navigated event is an appropriate place for this code. You will also need to set the
IsWebBrowserContextMenuEnabled
property to stop the context menu popping up after your
WebDocument_MouseDown
event has been processed