做一個窗體模板,假設(shè)是Form2
成都創(chuàng)新互聯(lián)公司專注于網(wǎng)站建設(shè),為客戶提供成都做網(wǎng)站、成都網(wǎng)站制作、網(wǎng)頁設(shè)計開發(fā)服務(wù),多年建網(wǎng)站服務(wù)經(jīng)驗,各類網(wǎng)站都可以開發(fā),品牌網(wǎng)站設(shè)計,公司官網(wǎng),公司展示網(wǎng)站,網(wǎng)站設(shè)計,建網(wǎng)站費(fèi)用,建網(wǎng)站多少錢,價格優(yōu)惠,收費(fèi)合理。
Dim x as New Form2
x.Show()
如果彈出窗口較多,x可以用動態(tài)數(shù)組替代
下面這段代碼完成,在窗體上用語句添加2個 GroupBox控件,且在每個GroupBox控件中添加4個 RadioButton 控件。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
'添加2個GroupBox
Dim MyGroupBox(2) As GroupBox
For i = 1 To 2
'將一個GroupBox控件加入到Form上
MyGroupBox(i) = New GroupBox
Me.Controls.Add(MyGroupBox(i))
'設(shè)置該GroupBox控件的屬性
MyGroupBox(i).Height = 240
MyGroupBox(i).Width = 600
MyGroupBox(i).Top = (i - 1) * (240 + 20) + 20
MyGroupBox(i).Left = 20
'修改新加入控件的Text值
MyGroupBox(i).Text = "GroupBox" CStr(i)
Next
'每個GroupBox中添加4個單選按鈕
Dim MyRadioButton1(4) As RadioButton
Dim MyRadioButton2(4) As RadioButton
For i = 1 To 4
MyRadioButton1(i) = New RadioButton
Me.Controls.Add(MyRadioButton1(i))
MyRadioButton1(i).Parent = MyGroupBox(1)
'設(shè)置該GroupBox控件的屬性
MyRadioButton1(i).Height = 20
MyRadioButton1(i).Width = 120
MyRadioButton1(i).Top = (i - 1) * (20 + 20) + 40
MyRadioButton1(i).Left = 20
'修改新加入控件的Text值
MyRadioButton1(i).Text = "RadioButton1_" CStr(i)
Next
For i = 1 To 4
MyRadioButton2(i) = New RadioButton
Me.Controls.Add(MyRadioButton2(i))
MyRadioButton2(i).Parent = MyGroupBox(2)
'設(shè)置該GroupBox控件的屬性
MyRadioButton2(i).Height = 20
MyRadioButton2(i).Width = 120
MyRadioButton2(i).Top = (i - 1) * (20 + 20) + 40
MyRadioButton2(i).Left = 20
'修改新加入控件的Text值
MyRadioButton2(i).Text = "RadioButton2_" CStr(i)
Next
End Sub
1,添加一個模塊,在模塊里聲明一個全局公共變量N;
2,在控件的調(diào)用窗體代碼段里,把此控件名稱給這個全局公共變量N賦值;
3,在窗體的Load()事件里,寫代碼: Me.Text = N。