先定义一个控件(Option1),然后修改index值为0 ,就创建了控件数组,设置你要创建控件数组的其它属性.\x0d\x0aPrivate Sub Form_Load()\x0d\x0a Dim i%\x0d\x0a For i = 1 To 3\x0d\x0a Load Option1(i) 这句是关键,,,,,\x0d\x0a Option1(i).Top = Option1(0).Top\x0d\x0a Option1(i).Left = Option1(i - 1).Left + Option1(i - 1).Width + 200\x0d\x0a Option1(i).Visible = True\x0d\x0a Next\x0d\x0a Option1(0).Caption = "10"\x0d\x0a Option1(1).Caption = "15"\x0d\x0a Option1(2).Caption = "20"\x0d\x0a Option1(3).Caption = "30"\x0d\x0a End Sub\x0d\x0a\x0d\x0aPrivate Sub Option1_Click(Index As Integer)\x0d\x0a Text1.FontSize = Val(Option1(Index).Caption)\x0d\x0aEnd Sub
我们提供的服务有:网站设计、做网站、微信公众号开发、网站优化、网站认证、王屋ssl等。为上千余家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的王屋网站制作公司
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Label1 As New Label
Label1.Location = New System.Drawing.Point(8, 8) '括号中写左边距和上边距
Label1.Name = "Label1"
Label1.AutoSize = True
Label1.TabIndex = 1
Label1.Text = "运输"
Label1.Visible = True
Me.Controls.Add(Label1)
End Sub
Option Explicit
Private WithEvents NewTextBox As TextBox
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮
Private Sub Command1_Click()
If NewTextBox Is Nothing Then
Set NewTextBox = Controls.Add("VB.TextBox", "cmdNew", Form1)
NewTextBox.Move 200, 200
NewTextBox.Width = Form1.Width - 450
NewTextBox.Height = Form1.Height - 1400
NewTextBox.Visible = True
End If
End Sub
Private Sub Command2_Click()
If NewTextBox Is Nothing Then
Exit Sub
Else
Controls.Remove NewTextBox
Set NewTextBox = Nothing
End If
End Sub
我从来不加到Controls中也能用,大概这个不是从Control继承而来的,所有非可视部件(即组件)估计都不需要add。