A
Anthony P.
Hello Everyone,
I'm building an application and need to keep track of the amount of
text in a textbox to make sure the user knows how many characters they
have left to type. I've set the textbox's max length to 120 and that
works fine. Now, I have a label that displays characters remaining in
the textbox. For each keypress I am decrementing the counter (and
label value) by one and when the user presses the backspace key, I am
incrementing it by one. The problem is that when the user presses a
key combination (like shift+letter to capitialize something) it is
considered two kepresses (which is right, but unwanted for counting
reasons).
Can someone tell me how to NOT COUNT the pressing of modification keys
like shift, alt, etc? Here is the code I'm using:
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Back And labelCharactersRemaining.Text <
120 Then
labelCharactersRemaining.Text =
labelCharactersRemaining.Text + 1
Else
labelCharactersRemaining.Text =
labelCharactersRemaining.Text - 1
End If
End Sub
I am sure it's something simple. I just can't figure it out.
Thanks!
Anthony Papillion
I'm building an application and need to keep track of the amount of
text in a textbox to make sure the user knows how many characters they
have left to type. I've set the textbox's max length to 120 and that
works fine. Now, I have a label that displays characters remaining in
the textbox. For each keypress I am decrementing the counter (and
label value) by one and when the user presses the backspace key, I am
incrementing it by one. The problem is that when the user presses a
key combination (like shift+letter to capitialize something) it is
considered two kepresses (which is right, but unwanted for counting
reasons).
Can someone tell me how to NOT COUNT the pressing of modification keys
like shift, alt, etc? Here is the code I'm using:
Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Back And labelCharactersRemaining.Text <
120 Then
labelCharactersRemaining.Text =
labelCharactersRemaining.Text + 1
Else
labelCharactersRemaining.Text =
labelCharactersRemaining.Text - 1
End If
End Sub
I am sure it's something simple. I just can't figure it out.
Thanks!
Anthony Papillion