我正在开发我的第一个VB程序。我有一个带面板的表格。我认为该面板是一系列面板,当单击一个继续按钮时会打开。
像这样:
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Main Panel Layout'
pnlMain.Location = New System.Drawing.Point(5, 150)
pnlMain.Name = "pnlMain"
pnlMain.Size = New System.Drawing.Size(600, 525)
pnlMain.BackColor = Color.White
pnlMain.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
pnlMain.AutoScroll = True
'Sub Panel Layout'
pnlSub.Location = New System.Drawing.Point(610, 150)
pnlSub.Name = "pnlSub"
pnlSub.Size = New System.Drawing.Size(648, 525)
pnlSub.BackColor = Color.Gainsboro
pnlSub.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
'Layout Step 1 Panel'
pnlStep_1.Location = New System.Drawing.Point(2, 2)
pnlStep_1.Name = "pnlStep_1"
pnlStep_1.Size = New System.Drawing.Size(579, 100)
pnlStep_1.BackColor = Color.Gainsboro
pnlStep_1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
'Layout Step 1 Label'
lblStep_1.Location = New Point(230, 38)
lblStep_1.Text = "Step l"
lblStep_1.Size = New Size(137, 24)
lblStep_1.Font = New Font(lblStep_1.Font.FontFamily, 14, FontStyle.Bold)
'Layout Step 1 Button"
btnStep_1_Cont.Location = New Point(502, 73)
btnStep_1_Cont.Text = "Continue"
btnStep_1_Cont.Size = New Size(75, 25)
btnStep_1_Cont.BackColor = Color.WhiteSmoke
'Create Instane of Base Panels'
Me.Controls.Add(pnlMain)
Me.Controls.Add(pnlSub)
'Create Instances of Step 1 Controls'
pnlMain.Controls.Add(pnlStep_1)
pnlStep_1.Controls.Add(lblStep_1)
pnlStep_1.Controls.Add(btnStep_1_Cont)
'Create Button Events for Step 1'
AddHandler btnStep_1_Cont.Click, AddressOf btnStep_1_Cont_Click
End Sub
Private Sub btnStep_1_Cont_Click(ByVal sender As Object, ByVal e As EventArgs)
'Layout Step 2 Panel'
pnlStep_2.Location = New System.Drawing.Point(2, 27)
pnlStep_2.Name = "pnlStep_2"
pnlStep_2.Size = New System.Drawing.Size(579, 100)
pnlStep_2.BackColor = Color.Gainsboro
pnlStep_2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
'Layout Step 2 Label'
lblStep_2.Location = New Point(21, 38)
lblStep_2.Text = "Step 2"
lblStep_2.Size = New Size(554, 24)
lblStep_2.Font = New Font(lblStep_2.Font.FontFamily, 14, FontStyle.Bold)
'Layout Step 2 Button"
btnStep_2_Cont.Location = New Point(502, 73)
btnStep_2_Cont.Text = "Continue"
btnStep_2_Cont.Size = New Size(75, 25)
btnStep_2_Cont.BackColor = Color.WhiteSmoke
'Create Instances of Step 2 Controls'
pnlMain.Controls.Add(pnlStep_2)
If pnlMain.Contains(pnlStep_1) Then
pnlStep_2.BringToFront()
End If
pnlStep_2.Controls.Add(lblStep_2)
pnlStep_2.Controls.Add(btnStep_2_Cont)
'Create Button Events for Step 2'
AddHandler btnStep_2_Cont.Click, AddressOf btnStep_2_Cont_Click
End Sub
等等......
这将有50多个步骤。一段时间后会变得相当混乱和重复。有没有办法创建一个类创建面板并从最后一个顶部放置一定数量的px?然后打电话给那个班,让他们上来。
对于其余的控件,我可以为它们创建一个类,只需输入参数。
使用标签和按钮,有些可能有两个或三个按钮和最多四个标签。
提前完成
拉布
答案 0 :(得分:0)
是的,你可以,你不需要创建一个class
,你只需要重复panel class
dim myPanel as Panel
for i = 0 to 20
myPanel = new Panel
myPanel.Location = New System.Drawing.Point(5*i, 150*i) '' or set you grid as you want
myPanel.Name = "Panel" & i
myPanel.Size = New System.Drawing.Size(600, 525)
myPanel.BackColor = Color.White
myPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
myPanel.AutoScroll = True
me.Controlls.Add(myPanel)
next