Link to home
Start Free TrialLog in
Avatar of felipes
felipes

asked on

Preventing Ctrl-V

 I'm creating a kind of text editor, and I'm using RichTextBox to make colored text. I want to use my own procedures to copy data to clipboard (for various reasons), so I want to disable the hotkeys (ctrl-v, ctrl-c, etc) to copy/paste/cut from the RichTextBox, how can I do it?
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

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 mcrider
mcrider

Actually what I gave you will work for textboxes not RichTextBoxes... To do the same for RichTextBoxes, to this in the KEYDOWN EVENT:

    If KeyCode = 86 And Shift = 2 Then
        KeyCode = 0
        Shift = 0
        Debug.Print "CTRL-V WAS PRESSED"
    End If


Cheers!
By the way, the code for intercepting CTRL-C is:

    If KeyCode = 67 And Shift = 2 Then
        KeyCode = 0
        Shift = 0
        Debug.Print "CTRL-C WAS PRESSED"
    End If


Also in the KEYDOWN EVENT...


Cheers!
Avatar of felipes

ASKER

 This doesn't work!
Did you try the keydown event I gave you???
Avatar of felipes

ASKER

 Yes, I Tried in KeyUP, KeyDown and KeyPress.
The code I gave you works perfectly on my VB5 system with SP3 installed... What version are you running?
Start a new project...

Add a RichTextBox to Form1.

Put the following code in the DECLARATION SECTION of FORM1:

Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 86 And Shift = 2 Then
        KeyCode = 0
        Shift = 0
        MsgBox "CTRL-V WAS INTERCEPTED"
    End If
    If KeyCode = 67 And Shift = 2 Then
        KeyCode = 0
        Shift = 0
        MsgBox "CTRL-C WAS INTERCEPTED"
    End If
End Sub


If this doesn't work, you've got big problems...


Cheers!
Avatar of felipes

ASKER

 Strange, now it works!!! Thanks!
Thanks for the points! Glad I could helps!


Cheers!