Disable Select All (CTRL + A) and Copy (CTRL + C) in WebBrowser Component in VB6

khairil used Ask the Experts™
I have developed an application using Webbroswer control (which inherit Internet Explorer) as main interface. The application is in VB6 - upgrade to .net is not the choice. I like user to access web page contain it load but do not want them to copy the content.

I've successfully disable mouse context menu, but user still be able to press CTRL to select all and copy the content. How can I prevent this? Is there VB6 code that can prevent user from pressing CTRL + A and CTRL + C, without other side effect to the application (such disable select all in text box)?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

You have to dive into HTMLDocument events.
Try the following code:

Private WithEvents doc As HTMLDocument

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Set doc = WebBrowser1.Document
End Sub

Private Sub doc_onkeydown()
    Dim eventObj As IHTMLEventObj
    Set eventObj = doc.parentWindow.event
    If eventObj.ctrlKey And ((eventObj.keyCode = vbKeyA) Or (eventObj.keyCode = vbKeyC)) Then
        eventObj.returnValue = False
    End If
End Sub

Sorry, I forgot to mention you'll have to add a reference to "Microsoft HTML Object Library" (MSHTML.TLB).



Already add the type lib for that and it works like CHARM. Thanks a lot man. User still can do selection by dragging mouse pointer but they cannot copy it now.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial