Hi ,
i have used this code in textbox_keypress event and it's works fine
i try to add same code to a function like "TextBox_Numeric_Only" , to use it in my froms textboxes .
but the code not work !!
can u help me please
i have used this code in textbox_keypress event and it's works fine
Code:
Dim tb As TextBox = sender
If Not Char.IsDigit(e.KeyChar) Then e.Handled = True
If e.KeyChar = Chr(8) Then e.Handled = False 'allow Backspace
If e.KeyChar = "-" And tb.SelectionStart = 0 Then e.Handled = False
If e.KeyChar = "." And tb.Text.IndexOf(".") = -1 Then e.Handled = Falsei try to add same code to a function like "TextBox_Numeric_Only" , to use it in my froms textboxes .
Code:
Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
e.Handled = TextBox_Numeric_Only(sender, e)
End Sub
Public Function TextBox_Numeric_Only(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) As Boolean
Dim tb As TextBox = sender
If Not Char.IsDigit(e.KeyChar) Then e.Handled = True
If e.KeyChar = Chr(8) Then e.Handled = False 'allow Backspace
If e.KeyChar = "-" And tb.SelectionStart = 0 Then e.Handled = False
If e.KeyChar = "." And tb.Text.IndexOf(".") = -1 Then e.Handled = False
End Functionbut the code not work !!
can u help me please