A simple method is to trap the WM_RBUTTONDOWN and WM_RBUTTONDBLCLK messages at the application level. You can add a message filter to your application using the statement Application.AddMessageFilter(instance of IMessageFilter). In the example below, the ImessageFilter interferace is implemented by the form containing the AXWebrowser control. As the filter is application wide, it is added/removed when the form activates/deactivates.
Public Class Form1
Implements IMessageFilter
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
Const WM_RBUTTONDOWN As Int32 = &H204
Const WM_RBUTTONDBLCLK As Int32 = &H206
' check that the message is WM_RBUTTONDOWN Or WM_RBUTTONDBLCLK
' verify AxWebBrowser1 is not null
' verify the target is AxWebBrowser1
Return (m.Msg = WM_RBUTTONDOWN OrElse m.Msg = WM_RBUTTONDBLCLK) AndAlso (AxWebBrowser1 IsNot Nothing) AndAlso (AxWebBrowser1 Is Control.FromChildHandle(m.HWnd))
End Function
Protected Overrides Sub OnActivated(e As EventArgs)
MyBase.OnActivated(e)
' Filter is application wide, activate filter with form
Application.AddMessageFilter(Me)
End Sub
Protected Overrides Sub OnDeactivate(e As EventArgs)
MyBase.OnDeactivate(e)
' Filter is application wide, remove when form not active
Application.RemoveMessageFilter(Me)
End Sub
End Class