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
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.
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
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
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.
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
Re: How to enable Ctrl+C, Ctrl+V, Ctrl+X in a text box?
Quote:
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.