Dim btnObj As Control
Public Sub NewTextBox(ByVal CtrlName As String)
Set btnObj = Me.Controls.Add("Forms.TextBox.1", "TextBoxName")
With btnObj
.Text = Text1.Text
.Top = 100
.Left = 100
.Visible = True
End With
End Sub
Private Sub Text1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then NewTextBox TxtCtrl
End Sub
如果控件很多建议使用控件数组,然后通过load方法加载
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii = 13 Then
Load Text1(Index + 1)
With Text1(Index + 1)
.Visible = True
.Top = Text1(Index).Top + Text1(Index).Height + 10
.Left = Text1(Index).Left
End With
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then NewTextBox "text1234"
End Sub
Public Sub NewTextBox(ByVal CtrlName As String)
Dim btnObj As Control
Set btnObj = Me.Controls.Add("VB.TextBox", CtrlName)
With btnObj
.Text = Text1.Text
.Top = Text1.Top + Text1.Height + 200
.Left = Text1.Left
.Height = Text1.Height
.Width = Text1.Width
.Visible = True
End With
End Sub
Public Sub NewTextBox(ByVal CtrlName As String)
Dim btnObj As Control
Set btnObj = Me.Controls.Add("VB.TextBox", "TextBoxName")
With btnObj
.Text = Text1.Text
.Top = Text1.Top + 200
.Left = Text1.Left
.Visible = True ‘改成TRUE
End With
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then NewTextBox CtrlName
End Sub
Public Sub NewTextBox(ByVal CtrlName As String)
Dim btnObj As Control
Set btnObj = Me.Controls.Add("VB.TextBox", "TextBoxName")
With btnObj
.Text = Text1.Text
.Top = 100
.Left = 100
.Visible = False
End With
End Sub