先定義一個(gè)控件(Option1),然后修改index值為0 ,就創(chuàng)建了控件數(shù)組,設(shè)置你要?jiǎng)?chuàng)建控件數(shù)組的其它屬性.\x0d\x0aPrivate Sub Form_Load()\x0d\x0a Dim i%\x0d\x0a For i = 1 To 3\x0d\x0a Load Option1(i) 這句是關(guān)鍵,,,,,\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
我們提供的服務(wù)有:網(wǎng)站設(shè)計(jì)、做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、王屋ssl等。為上千余家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的王屋網(wǎng)站制作公司
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) '括號(hào)中寫左邊距和上邊距
Label1.Name = "Label1"
Label1.AutoSize = True
Label1.TabIndex = 1
Label1.Text = "運(yùn)輸"
Label1.Visible = True
Me.Controls.Add(Label1)
End Sub
Option?Explicit
Private?WithEvents?NewTextBox?As?TextBox
'通過(guò)使用WithEvents關(guān)鍵字聲明一個(gè)對(duì)象變量為新的命令按鈕
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
我從來(lái)不加到Controls中也能用,大概這個(gè)不是從Control繼承而來(lái)的,所有非可視部件(即組件)估計(jì)都不需要add。