How to create user control textbox that accept only numeric characters

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



Answer this question

How to create user control textbox that accept only numeric characters

  • WingingIT

    sorry for replying twice, I cannot able to delete one.

  • 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.KeyPress

    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then

    e.Handled = True

    else

    e.Handled = False

    End If

    End Sub



  • wolf777

    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.KeyPress

    If Not IsNumeric(e.KeyChar) Then

    e.Handled = True

    End If

    End Sub



  • comspy

    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.KeyPress

    If (KeyAscii < 48 Or KeyAscii > 57) And KeyAscii <> 8 Then

    e.Handled = True

    else

    e.Handled = False

    End If

    End Sub



  • How to create user control textbox that accept only numeric characters