Displaying number in the textbox

jdy0803

Well-known member
Joined
Sep 9, 2012
Messages
73
Location
Santa Clarita
Programming Experience
10+
There is a TextBox which have focus.
If press number(0~9), that number should be displayed.
I should do this in keydown event.
If click number, currently pressed number should be displayed, not accumulated number.
for example, press 1, then display 1
press 2, then display 2(not 12)
press 3, then display 3(not 123)


How could I do this in keydown event?
 
This may or may not be acceptable to you but probably the simplest way to achieve this would be to set the MaxLength property to 1 and then handle the TextChanged and Enter events and call SelectAll. That way, when the user types a character the text will automatically be selected, meaning that it will be overwritten when the user types another character, e.g.
Private Sub SelectTextBoxText(sender As Object, e As EventArgs) Handles TextBox1.Enter, TextBox1.TextChanged
    TextBox1.SelectAll()
End Sub
 
Back
Top