Option Explicit
Private WithEvents txt As TextBox
Private Sub Form_Load()
Dim i, j
For i = 1 To 5
'Set txt = Nothing
Set txt = Form1.Controls.Add("vb.textbox", "txt" & i)
With txt
.Top = j + 400
.Left = j + 400
.Height = 400
.Width = 400
.Visible = True
End With
j = txt.Top
Next
End Sub
Private Sub txt_Click()
Select Case txt.Name
Case "txt1"
MsgBox txt.Name
Case "txt2"
MsgBox txt.Name
Case "txt3"
MsgBox txt.Name
End Select这段代码是动态的在窗体上添加了5 个文本框
怎么样获取他们的事件
Private WithEvents txt As TextBox
Private Sub Form_Load()
Dim i, j
For i = 1 To 5
'Set txt = Nothing
Set txt = Form1.Controls.Add("vb.textbox", "txt" & i)
With txt
.Top = j + 400
.Left = j + 400
.Height = 400
.Width = 400
.Visible = True
End With
j = txt.Top
Next
End Sub
Private Sub txt_Click()
Select Case txt.Name
Case "txt1"
MsgBox txt.Name
Case "txt2"
MsgBox txt.Name
Case "txt3"
MsgBox txt.Name
End Select这段代码是动态的在窗体上添加了5 个文本框
怎么样获取他们的事件
Private Sub txt_Change()End Sub
。。
Private txt As TextBox
Private WithEvents txt1 As TextBox
Private WithEvents txt2 As TextBox
Private Sub Form_Load()
Dim i, j
For i = 1 To 2
'Set txt = Nothing
Set txt = Form1.Controls.Add("vb.textbox", "txt" & i)
With txt
.Top = j + 400
.Left = j + 400
.Height = 400
.Width = 400
.Visible = True
End With
j = txt.TopIf i = 1 Then
Set txt1 = txt
ElseIf i = 2 Then
Set txt2 = txt
End If
Next
End SubPrivate Sub txt1_LostFocus()
MsgBox txt1.Name
End SubPrivate Sub txt2_LostFocus()
MsgBox txt2.Text
End Sub