Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 textbox numeric value issue

$
0
0
Hi ,

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 = False


i 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 Function


but the code not work !!

can u help me please

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>