VB经验谈:限制输入的文本框
PublicClassMyTextBox
InheritsSystem.Windows.Forms.TextBox
Privatem_strValidTextAsString="0123456789. -"&Chr(13).ToString
Privatem_blnEditableAsBoolean=True
#Region"Windows窗体设计器生成的代码"
PublicSubNew()
MyBase.New()
'该调用是Windows窗体设计器所必需的。
InitializeComponent()
'在InitializeComponent()调用之后添加任何初始化
EndSub
'UserControl1重写dispose以清理组件列表。
ProtectedOverloadsOverridesSubDispose(ByValdisposingAsBoolean)
IfdisposingThen
IfNot(componentsIsNothing)Then
components.Dispose()
EndIf
EndIf
MyBase.Dispose(disposing)
EndSub
'Windows窗体设计器所必需的
PrivatecomponentsAsSystem.ComponentModel.IContainer
'注意:以下
'可以使用Windows窗体设计器修改此过程。
'不要使用代码编辑器修改它。
PrivateSubInitializeComponent()
components=NewSystem.ComponentModel.Container
EndSub
#EndRegion
PrivateSubMyTextBox_KeyPress(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.KeyPressEventArgs)HandlesMyBase.KeyPress
DimstrLocalStringAsString
IfEditAbleThen
strLocalString=m_strValidText&Chr(8).ToString
Else
strLocalString=m_strValidText
EndIf
IfUCase(strLocalString).IndexOf(UCase(e.KeyChar))<0Then
e.Handled=True
Beep()
Else
EndIf
EndSub
PublicPropertyValidText()AsString
Get
Returnm_strValidText
EndGet
Set(ByValValueAsString)
m_strValidText=Value
EndSet
EndProperty
PublicPropertyEditAble()AsBoolean
Get
Returnm_blnEditable
EndGet
Set(ByValValueAsBoolean)
m_blnEditable=Value
EndSet
EndProperty
EndClass
- 最新文章
- 用VB获取桌面图象[04-17]
- 用VB5.0从Recordset中打印列表[04-17]
- 巧用VBA自动处理Word表格[04-17]
- VB中资源文件的具体使用方法[04-17]
- VB编程的一些基础的问题[04-17]
- 把符串中的一子串替换为另一子串[04-17]
- 相关文章
