|
类模块代码
- Private WithEvents ufr As MSForms.UserForm
- Private WithEvents xTxtBox As MSForms.TextBox
- Public Sub Attach(ByVal f As MSForms.UserForm, ByVal c As MSForms.TextBox)
- Set ufr = f
- Set xTxtBox = c
- End Sub
- Rem:文本框限制输入数字
- Private Sub xTxtBox_Change()
- If Not IsNumeric(xTxtBox.Value) Then
- xTxtBox.Value = ""
- MsgBox "请键入<≥0的数字>!"
- End If
- End Sub
- Rem:点击全选
- Private Sub xTxtBox_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
- xTxtBox.SelStart = 0
- xTxtBox.SelLength = Len(xTxtBox)
- End Sub
复制代码
模块代码(N个TextBox)
- Dim c() As New TextBoxClass
- Public Sub TextBoxLoad(ByVal f As MSForms.UserForm)
- Dim ctl As Control, n%
- For Each ctl In f.Controls
- If TypeName(ctl) = "TextBox" Then
- n = n + 1: ReDim Preserve c(1 To n)
- c(n).Attach f, ctl
- End If
- Next
- End Sub
复制代码
3个(乃至N个)窗体代码
- Private Sub UserForm_Initialize()
- Call TextBoxLoad(Me)
- End Sub
复制代码
|
|