PublicClass NumberTextBoxClass NumberTextBox Inherits System.Windows.Forms.TextBox Windows 窗体设计器生成的代码#Region " Windows 窗体设计器生成的代码 " PublicSub New()SubNew() MyBase.New() '该调用是 Windows 窗体设计器所必需的。 InitializeComponent() '在 InitializeComponent() 调用之后添加任何初始化 End Sub 'UserControl 重写 dispose 以清理组件列表。 ProtectedOverloadsOverridesSub Dispose()Sub Dispose(ByVal disposing AsBoolean) If disposing Then IfNot (components IsNothing) Then components.Dispose() EndIf EndIf MyBase.Dispose(disposing) End Sub 'Windows 窗体设计器所必需的 Private components As System.ComponentModel.IContainer '注意: 以下过程是 Windows 窗体设计器所必需的 '可以使用 Windows 窗体设计器修改此过程。 '不要使用代码编辑器修改它。 <System.Diagnostics.DebuggerStepThrough()>PrivateSub InitializeComponent()Sub InitializeComponent() components =New System.ComponentModel.Container() End Sub #End Region PrivateSub NumberTextbox_KeyPress()Sub NumberTextbox_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) HandlesMyBase.KeyPress If (e.KeyChar <"0"Or e.KeyChar >"9") And e.KeyChar <>Chr(8) And e.KeyChar <>Chr(46) Then e.Handled =True EndIf IfInStr(1, Me.Text, ".") >0And e.KeyChar =Chr(46) Then e.Handled =True End Sub PrivateSub NumberTextbox_TextChanged()Sub NumberTextbox_TextChanged(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMyBase.TextChanged IfMe.Text.StartsWith(".") Then Me.Text ="0." SendKeys.Send("{End}") EndIf IfMe.Text.Length >=2Then IfMe.Text.Substring(1, 1) <>"."AndMe.Text.Substring(0, 1) ="0"Then SendKeys.Send("{BS}") EndIf EndIf IfMe.Text =""Then Me.Text =0 Me.Focus() Me.Select(0, 1) 'SendKeys.Send("{End}") EndIf End Sub End Class
重写Textbox控件,只能输入数字
posted on
2007-06-19 14:15小黑三
阅读(494)
评论(0)
编辑收藏举报