Link to home
Start Free TrialLog in
Avatar of khairil
khairilFlag for Malaysia

asked on

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

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)?

-khairil-
Avatar of rafunk
rafunk
Flag of Italy image

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

ASKER CERTIFIED SOLUTION
Avatar of rafunk
rafunk
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of khairil

ASKER

Hi,

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.

-khairil-