-1
我正在開發我的第一個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
末次
等等......
這將對它超過50步。在一段時間之後,它會變得相當混亂和重複。有沒有辦法創建一個類創建面板,並從最後一個頂部放置一定數量的px?然後給那個班打電話讓他們出來
對於其餘的控件,我可以爲它們創建一個類並輸入參數。
使用標籤和按鈕,一些可能會有兩個或三個按鈕和最多四個標籤。
提前感謝名單
拉布
可能是你最好的選擇是創建一個用戶控制每一步。您可以像使用表單一樣將用戶控件添加到項目中,並且您也可以按照相同的方式進行設計。一旦你建立了你的項目,你可以像使用其他控件一樣使用你的用戶控件,把它添加到設計器中的表單或者用代碼創建它。您可以一次添加所有步驟,但所有這些控件都可能會減慢整個過程。我建議在該步驟完成時刪除步驟的用戶控件,併爲代碼中的下一步創建和添加用戶控件。 – jmcilhinney