Private Sub txtText_KeyUp(KeyCode As Integer, Shift As Integer)
' Check for Ctrl.
If Shift = vbCtrlMask Then
' Check KeyCode.
Select Case KeyCode
Case 65 ' Ctrl+A
' Select all text.
TextBoxSelectAll txtText
Case 67 ' Ctrl+C
' Copy selected text or copy all text
' if no text is selected.
If txtTextBox.SelLength = 0 Then
TextBoxCopyAll txtText
Else
TextBoxCopySelected txtText
End If
End Select
End If
End Sub
Private Sub txtText_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
' check for right button click.
If Button = 2 And txtText.SelLength = 0 Then
' Select all text.
TextBoxSelectAll txtText
End If
End Sub
Public Sub TextBoxSelectAll(ByVal txtTextBox As TextBox)
' Select all text.
txtTextBox.SelStart = 0
txtTextBox.SelLength = Len(txtText.Text)
End Sub
Public Sub TextBoxCopyAll(ByVal txtTextBox As TextBox)
' Copy all text to clipboard.
Clipboard.Clear
Clipboard.SetText txtTextBox.Text
End Sub
Public Sub TextBoxCopySelected(ByVal txtTextBox As TextBox)
' Copy selected text to clipboard.
Clipboard.Clear
Clipboard.SetText txtTextBox.SelText
End Sub