How to create user control textbox that accept only numeric characters and has all his properties and methods
i create that but
how can i add textbox properties and methods in my user control
How to create user control textbox that accept only numeric characters and has all his properties and methods
i create that but
how can i add textbox properties and methods in my user control
How to create user control textbox that accept only numeric characters
WingingIT
rekhareflection
create a class of you own and inherit it from TextBox
and Override the KeyPress event and write the code there to accept only the numeric key value.
Private
Sub myTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPressIf (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
e.Handled = Trueelse
e.Handled = False End If End Subwolf777
a better way is this:
implement the keypress event. Then do this:
if Char.IsDigit(e.KeyCode) = false then
e.Handled = true
end if
Andrew Stanford
you can simplify by using the isnumeric function:
Private
Sub myTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPressIf Not IsNumeric(e.KeyChar) Then
e.Handled = True End If End Subcomspy
create a class of you own and inherit it from TextBox
and Override the KeyPress event and write the code there to accept only the numeric key value.
Private
Sub AdvTextBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPressIf (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then
e.Handled = Trueelse
e.Handled = False End If End Sub