-
I'm having the presentaition of my program tomorow and i noticed that one thing is not finished. I just must finsh it until tomorow. You are my last chance.
I have 1 textbox
Problem:
I need to make program wich disalows user to copy information from textbox to clipboard.
(I need to make right mouse button and Ctrl+c
keys inactive on this textbox)
I tried to make something like:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 2 Then
KeyAscii = 0
End If
End Sub
But this just doesn't work
Any ideas apricieted
-thank you
------------------
-casparas
novice programer
[email protected]
-
The way to disable the right click menu is here: http://www.vb-world.net/tips/tip131.html
As for disabling the ctrl+C and ctrl+x functions, keep in mind that the ctrl key and c key can be pressed at different times so long as the ctrl is pressed first and released last. Try this:
Option Explicit
Dim ctrlDown As Boolean
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'Set ctrlDown to "True" until the KeyUp
'even is called to release it.
If Shift = 2 Then ctrlDown = True
End Sub
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyC And ctrlDown = True Then
'User pressed ctrl+C ... clear clipboard
Clipboard.Clear
Beep
End If
If KeyCode = vbKeyX And ctrlDown = True Then
'User pressed ctrl+X ... restore text
'and clear clipboard
Text1.Text = Clipboard.GetText
Clipboard.Clear
Beep
End If
'check if ctrl key was released
If Shift = 2 Then ctrlDown = False
End Sub
Good luck!
------------------
Micah Carrick
http://micah.carrick.com
[email protected]
ICQ: 53480225
-
Or you could just set the ENABLED property of the textbox to FALSE, or just use a label instead.
-
quite :)
just do text1.enabled = false..?
or subclass it and handle the message manually LOL :)
------------------
cintel rules :p
www.cintelsoftware.co.uk
-
Or you could just disable the control key on the keydown event:
Private Sub Text1_KeyDown(KeyCode as integer)
'not sure about the constant there... use the help
if KeyCode = vbKeyControl then KeyCode = 0
end sub
To set KeyCode = 0 cancels the key that was pressed....
-
Subclass the textbox, catch the WM_COPY message, and return 1 in the subclass (instead of calling the default windowproc).
This works pretty fine (I assume, I used it with the WM_PASTE message)
That's the easiest way.
The other way ic checking if Ctrl+C is pressed, or Ctrl+Insert is pressed.
-
Hi,
Keep this code in the keypress event of the text box:
Select Case KeyAscii
Case 3
DoEvents
Clipboard.GetText
Clipboard.Clear
MsgBox "You cannot copy items"
Case 22
KeyAscii = 0
End Select
------------
This works well and I hope this is what u need.
Regards,
Venkat.
------------------
[email protected]
ICQ: 45714766
http://venkat.iscool.net
-
Thank you very much everyone
------------------
-casparas
novice programer
[email protected]