Imports System.Globalization

Public Class NumTextBox
    Inherits TextBox

    Public Sub New()
        MyBase.New()
    End Sub

    Private _bolNumOnly As Boolean

    Public Property NumericOnly() As Boolean
        Get
            Return _bolNumOnly
        End Get
        Set(ByVal value As Boolean)
            _bolNumOnly = value
        End Set
    End Property

    Private Sub NumTextBox_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Handles MyBase.KeyPress
        If _bolNumOnly Then
            e.Handled = True
            If Char.IsNumber(e.KeyChar) Then
                e.Handled = False
                Exit Sub
            End If
            If e.KeyChar = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator Then
                If Me.Text.IndexOf(NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator) = -1 Then
                    e.Handled = False
                    Exit Sub
                End If
            End If
            If e.KeyChar = Chr(8) Then
                e.Handled = False
                Exit Sub
            End If
        End If
    End Sub

End Class
