2
Answers

How to add hot key function to my TextBox

KY

KY

14y
3.8k
1
Hey, everybody. I have a piece of VB code. What I want to do is to let the TextBox to accpet certain charaters. However, after I use the following code, the hot key like "Ctrl + V", "Ctrl + C", etc are no longer working. How can I modify the following code to let the Textbox support the hot keys from the Keyboard?

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Try
If Char.IsDigit(e.KeyChar) Or e.KeyChar = ". " Or e.KeyChar = Chr(8) Then
If e.KeyChar = ". " And InStr(Me.Text, ". ") > 0 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = True
End If
Catch ex As Exception
End Try
End Sub

Thank you very much in advance
Answers (2)