key down, suppress key problem
i have a telephone number textbox that i have used the key down event to suppress any other keys besides 0-9 and the backspace key. i have a label beside it.
i want to display a message on lbltelephone when the user presses an alphabetic key that the textbox is for numbers only,and the message should disapper when the user inputs correct values...
currently i have
e.suppresskeypress=true
lbltelephone.text="no"
Re: key down, suppress key problem
If keypress is invalid
do what you have done
Else
lbltelephone.text=""
end if
Re: key down, suppress key problem
this is the code i have, how do i incooperate your suggestion here?
Private Sub txtTel_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTel.KeyDown
If e.KeyCode = Keys.D0 Or e.KeyCode = Keys.D1 Or e.KeyCode = Keys.D2 Or e.KeyCode = Keys.D3 Or _
e.KeyCode = Keys.D4 Or e.KeyCode = Keys.D5 Or e.KeyCode = Keys.D6 Or e.KeyCode = Keys.D7 Or _
e.KeyCode = Keys.D8 Or e.KeyCode = Keys.D9 Or e.KeyCode = Keys.Back Then
Else
e.SuppressKeyPress = True
End If
If e.KeyCode = Keys.Escape Then
txtTel.Text = ""
End If
If e.KeyData = Keys.Return Then
txtPerson.Focus()
End If
End Sub
Re: key down, suppress key problem
@ Chris,
There was no need to start a new thread! I ask a mod to move the old one and have posted a vb.net solution in the thread here.
Edit:
See post #10.
Re: key down, suppress key problem
oh i didnt know, thanks, still xperiencing the same problem tho
Re: key down, suppress key problem
Code:
Private Sub txtTel_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTel.KeyDown
If e.KeyCode = Keys.D0 Or e.KeyCode = Keys.D1 Or e.KeyCode = Keys.D2 Or e.KeyCode = Keys.D3 Or _
e.KeyCode = Keys.D4 Or e.KeyCode = Keys.D5 Or e.KeyCode = Keys.D6 Or e.KeyCode = Keys.D7 Or _
e.KeyCode = Keys.D8 Or e.KeyCode = Keys.D9 Or e.KeyCode = Keys.Back Then
lbltelephone.Text = ""
Else
e.SuppressKeyPress = True
lbltelephone.Text = "No"
End If
If e.KeyCode = Keys.Escape Then
txtTel.Text = ""
End If
If e.KeyData = Keys.Return Then
txtPerson.Focus()
End If
End Sub
Re: key down, suppress key problem
What are you going to do if the user pastes a value into the textbox?