Hai friends,
Here is a solution to the common problem of disabling cut, copy and paste in a RichTextBox Control.
I had found it after certain experiments...
I hope, you all will like it..
Below is the code:
Code:
'Created by Akhilesh B Chandran
Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 45 And Shift = 1 Then KeyCode = 0 'paste(shift + insert)
If KeyCode = 45 And Shift = 2 Then KeyCode = 0 'copy(ctrl + insert)
If KeyCode = 86 And Shift = 2 Then KeyCode = 0 'paste(ctrl + v)
If KeyCode = 67 And Shift = 2 Then KeyCode = 0 'copy(ctrl + c)
If KeyCode = 88 And Shift = 2 Then KeyCode = 0 'cut(ctrl + x)
End Sub
Note: You have to set the AutoVerbMenu property of the Richtextbox control to False(for disabling the popup menu on right click)
Please post your comments and suggestions...
-Regards
Akhilesh B Chandran
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
I can still copy, cut and paste using the keyboard.
Just use 3 keys instead of 2, Control+Shift+The_Key
Not sure is this any better or not? >
Code:
Option Explicit
Private CntrlKey As Boolean
Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyControl Then
CntrlKey = True
End If
Select Case KeyCode
Case vbKeyZ, vbKeyX, vbKeyC, vbKeyV, vbKeyInsert
If CntrlKey = True Then KeyCode = 0
End Select
If (Shift And vbShiftMask) And vbKeyInsert Then
KeyCode = 0
End If
End Sub
Private Sub RichTextBox1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyControl Then
CntrlKey = False
End If
End Sub
Last edited by Edgemeal; Sep 12th, 2008 at 12:24 PM.
I didnt know that it was possible with 3 keys. Thanks for the code
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
another thing to paste
A
1) click on the textbox
2) shift + F10
3) click paste
B.
1) right click on the textbox
2) click on paste
We are discussing about Richtextbox And we have disabled the AutoVerbMenu (see post #1). So, no problem with that
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India
my bad. but im asking for textboxes on how to disable them
Did you tried searching this forum ? I think, it has been asked for several times.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video) My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet Social Group:VBForums - Developers from India