I'm using Visual Studio 2013 and writing in VB.NET. I am creating a project for an internship at school. Right now in one of my forms I have it where you must type in your name. Here's some pertinent information.
For the TextBox I do have Property of ShortcutsEnabled = False
so the user cannot copy and paste into the textbox if this is my problem then I'll just have to go without it. Now, I did this so it would make my errorchecking Sub simpler and more condensed so I wouldn't have to check for IsNumeric. The reason why I wouldn't have to check is because in the textboxes' KEYPRESS (not keydown) event I have it restricting what input is allowed.
Private Sub Nametxt_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Nametxt.KeyPress
Dim AllowedChars As String = "abcdefghijklmnopqrstuvwxyz" 'The characters that you are allowed to enter
If e.KeyChar <> ControlChars.Back And _
ModifierKeys <> Keys.Shift _
And e.KeyChar <> Chr(32) Then
'e.KeyChar <> ControlChars.Back allows the user to use the backspac
'ModifierKeys <> Keys.Shift allows the user to use the shift key so they can enter Capital letters
'e.KeyChar <> Chr(32) allows the user to use the space bar so they can enter their First and Last name.
If AllowedChars.IndexOf(e.KeyChar) = -1 Then
e.Handled = True
End If
Now, what I am trying to do is allow the user to also press "Ctrl+A" So that they can select all of the text in the box for convenience. Do remember that I have the textboxes' property of ShortcutsEnabled = False
This did not work:
If e.KeyChar <> ControlChars.Back And _
ModifierKeys <> Keys.Shift And _
e.KeyChar <> Chr(32) And _
New line --> (e.KeyChar <> Chr(61) AndAlso ModifierKeys <> Keys.Control)
Then
End If
Note: Because I am using the KEYPRESS event and not the keydown event, the only e.key
code that is viable is the e.keychar
||||| e.keycode
and e.keyvalue
are unusable in this event handler