假设你在窗体上添加一个PictureBox作为容器,添加一个按钮,代码如下:
Option
Explicit
'定义控件对象
Private
WithEvents
Text1
As
TextBox
Private
Sub
Command1_Click()
'动态添加控件
Set
Text1
=
Me.Controls.Add("VB.TextBox",
"Text1",
Picture1)
'设置该对象为可见
Text1.Visible
=
True
Text1.Top
=
200
Text1.Left
=
300
Text1.Text
=
"您好!"
End
Sub