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