Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable WebBrowser control context menu

Status
Not open for further replies.

felicitea

Programmer
Jun 13, 2002
9
US
How can I disable the context menu in the WebBrowser control? I'm using this control in a VB6 application to display an HTML file, but I don't want the user to get the context menu if they happen to right click on the control. Thanks.
 
I managed to find the answer to my own question and figured I'd post it in case anyone else needs it. First you set a reference in the project to Microsoft HTML Object Library. Then use the following code where BrowCtl is the name of your WebBrowser control:

'Declare a variable for the document property of
'the WebBrowser control
Private WithEvents htmlDoc As HTMLDocument

'Set the variable equal to the WebBrowser's
'document property
Private Sub brwLog_DocumentComplete(ByVal pDisp As Object, _ URL As Variant)
Set htmlDoc = BrowCtl.Document
End Sub

'Disable the document's oncontextmenu event
Private Function htmlDoc_oncontextmenu() As Boolean
htmlDoc_oncontextmenu = False
End Function
 
Nice tip.

I was able to remove a module that I was using to do this and saved 4 KB on my itty bitty app

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top