Numeric Text Box in vb.net

Numeric Text Box in vb.net Source Code

Numeric text box for only digits and specified decimals.
My Custom control can calculate expressions also
For Example, When you enter into textbox as 20.5+6/2 , Then it converts into 23.5 

See Full Source Code For Inventory Management System


Keypress Source Code in VB


 Private Sub sender_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress

        If e.KeyChar = Chr(Keys.Back) Then Exit Sub
        Dim EscKey As Boolean = False
        If e.KeyChar = Microsoft.VisualBasic.Chr(Keys.Escape) Then
            Me.FindForm.Dispose()
            EscKey = True
            GoTo ExitLbl
        End If
        If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
            sender.TopLevelControl.SelectNextControl(sender, True, True, True, True)
        End If
       
        If AllowSpecialChar = True Then

            If e.KeyChar = "+" Or e.KeyChar = "-" Or e.KeyChar = "/" Or e.KeyChar = "*" Or e.KeyChar = "(" Or e.KeyChar = ")" Then
                e.Handled = False
                Exit Sub
            ElseIf m_AllowPerSign = True Then
                If e.KeyChar = "%" Then
                    e.Handled = False
                    Exit Sub
                End If
            End If

        End If
        If sender.SelectionLength = Len(sender.text) Then
            If AllowNegative Then
                e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))) Xor (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart = 0))
            Else
                e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))))
            End If
            If AllowForQty Then
                e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))) Xor (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart <> 0))
            Else
                e.Handled = Not IsNumeric(e.KeyChar)
            End If
            Exit Sub
        End If
        '  Recently added start

        If AllowDecimal = True And sender.text.ToString.Contains(".") = True And IsContainSplCha(sender) = False Then
            If Len(sender.text.ToString.Substring(sender.text.ToString.IndexOf(".") + 1)) >= 2 Then
                e.Handled = True
                Exit Sub
            End If
        ElseIf IsContainSplCha(sender) = True Then
            If AllowDecimal = False Then
                If AllowNegative Then

                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart = 0))
                Else
                    e.Handled = Not IsNumeric(e.KeyChar)
                End If
                If AllowForQty Then

                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart <> 0))
                Else
                    e.Handled = Not IsNumeric(e.KeyChar)
                End If
            Else
                If AllowNegative Then
                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))) Xor (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart <> 0))
                Else
                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))))
                End If
                If AllowForQty Then
                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))) Xor (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart = 0))
                Else
                    e.Handled = Not IsNumeric(e.KeyChar)
                End If
                If e.KeyChar = "." Then e.Handled = False

            End If
        Else

            If AllowDecimal = False Then
                If AllowNegative Then

                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart = 0))
                Else
                    e.Handled = Not IsNumeric(e.KeyChar)
                End If
                If AllowForQty Then

                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart <> 0))
                Else
                    e.Handled = Not IsNumeric(e.KeyChar)
                End If
            Else
                If AllowNegative Then
                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))) Xor (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart = 0))
                Else
                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))))
                End If
                If AllowForQty Then
                    e.Handled = Not (IsNumeric(e.KeyChar) Or (e.KeyChar = "." And Not CBool(InStr(sender.Text, "."))) Xor (e.KeyChar = "-" And Not CBool(InStr(sender.Text, "-")) And sender.SelectionStart <> 0))
                Else
                    e.Handled = Not IsNumeric(e.KeyChar)
                End If
            End If
        End If

       

        If AllowPlusSign = True And e.KeyChar = "+" Then
            e.Handled = sender.SelectionStart And CBool(InStr(sender.Text, "+"))
        End If

        If e.KeyChar = Chr(&H8) Then e.Handled = False
        If Len(sender.Text) > MaxLength Then e.Handled = False
       


        Invalidate()
ExitLbl:

    End Sub



 For POS System in VB.NET Source Code

: Please Contact : 

sureshjyothijv@gmail.com