为了开发省力一点-数字输入框

 Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualBasic
Public Class numtbx
    Inherits System.Windows.Forms.TextBox

#Region " 组件设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        ' 该调用是组件设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    'Control 重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    '控件设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是组件设计器所必需的
    ' 可以使用组件设计器修改此过程。不要使用
    ' 代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    End Sub

#End Region
    Dim intdecimal As Int16 = 0
    Public Property DecimalLength() As Int16    '设置小数位
        Get
            DecimalLength = intdecimal
        End Get
        Set(ByVal Value As Int16)
            intdecimal = Value
        End Set
    End Property

    Protected Overrides Sub OnPaint(ByVal pe As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(pe)

        '在此添加自定义绘画代码
    End Sub
    Protected Overrides Sub onkeypress(ByVal e As KeyPressEventArgs)
        If IsNumeric(e.KeyChar) Then
            If MyBase.Text.Trim.IndexOf(".") > -1 Then
                If MyBase.Text.Trim.Length - MyBase.Text.Trim.IndexOf(".") - 1 >= intdecimal Then
                    e.Handled = True
                End If
            End If
        Else
            Select Case e.KeyChar
                Case "-"
                    If MyBase.Text.Trim.Length > 0 Then
                        e.Handled = True
                    End If
                Case "."
                    If MyBase.Text.Trim.IndexOf(".") > -1 Then
                        e.Handled = True
                    End If
                Case Microsoft.VisualBasic.ChrW(8)    'backspace

                Case Else
                    e.Handled = True
            End Select
        End If
    End Sub
End Class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值