|
-
Mar 9th, 2010, 06:38 AM
#1
Thread Starter
Hyperactive Member
How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box (Text1.Text)?
any idea please!
I found something, is correct ?
Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'Ctrl + A
If KeyCode = 65 And Shift = 2 Then '
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
KeyAscii = 0
End If
'Ctrl + C
If KeyCode = 67 And Shift = vbCtrlMask Then
Clipboard.Clear
Clipboard.SetText Text1.SelText
End If
'Ctrl + V
....
End Sub
-
Mar 9th, 2010, 07:30 AM
#2
Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
You don't have to write any code for this.
If you select the text and right mouse click, there is a default popup menu that contains Cut/Copy/Paste/Delete already there for you.
-
Mar 9th, 2010, 08:01 AM
#3
Addicted Member
Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
Ctrl+C; Ctrl+V; Ctrl+X; work fine without any codes in a Text1 on vb6...
The only thing you'll need is this: (For Ctrl+A).
Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 65 And Shift = 2 Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
 DoEvents
-
Mar 9th, 2010, 10:51 AM
#4
Thread Starter
Hyperactive Member
Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
Thanks. It important.
>>Ctrl+C; Ctrl+V; Ctrl+X; work fine without any codes in a Text1 on vb6...
But,
(1) Shift = 2 ?
(2) 'Ctrl + A' as same as Ctrl + a 97, is correct ?
Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 65 And Shift = 2 Then '65 = A"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
If KeyCode = 97 And Shift = 2 Then '97 = a"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
-
Mar 9th, 2010, 11:02 AM
#5
Addicted Member
Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
No need to do that. Just keep the "65".
(1) Shift = 2 Is for both "Ctrls".
(2) The keyboard sends the "65 KeyCode" when you press "a" whether its "A" Capital or not, so i don't think its gonna work with (If KeyCode = 97 And Shift = 2 Then). Just keep the first one.
 DoEvents
-
Mar 9th, 2010, 12:54 PM
#6
Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'This is critical - KeyPreview MUST be set to True
If (Shift And vbCtrlMask) = vbCtrlMask And KeyCode = vbKeyA Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
-
Mar 9th, 2010, 01:08 PM
#7
Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
 Originally Posted by Hack
Code:
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
'This is critical - KeyPreview MUST be set to True
If (Shift And vbCtrlMask) = vbCtrlMask And KeyCode = vbKeyA Then
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End If
End Sub
Hack, why must form's KeyPreview be set to True? This is a textbox keydown event, not the form's.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|