代码在线添加控件。
Dim WithEvents Text1 As TextBox
Dim WithEvents Label1 As Label
Dim WithEvents Command1 As CommandButton
'注意:这三句必须是全局声明,也就是在代码的最顶端通用的部分
Private Sub Form_Load()
Set Text1 = Me.Controls.Add("VB.TextBox", "Text1")
With Text1
.Visible = True
.Top = 0 '位置可以自己换大小也可以自己换,都不填就是默认的
.Left = 0
End With
Set Label1 = Me.Controls.Add("VB.Label", "Label1")
With Label1
.Visible = True
.Caption = "命令"
End With
Set Command1 = Me.Controls.Add("VB.CommandButton", "Command1")
With Command1
.Visible = True
.Caption = "按钮1"
End If
End Sub
就这两个