2014-02-06 94 views
1

如何控制此窗體的佈局,以便我的組框對齊垂直?Powershell窗體佈局

說我創建一個表單是這樣的:

$form = New-Object System.Windows.Forms.Form 

$groupBox1 = New-Object System.Windows.Forms.GroupBox 
$groupBox1.text = "Group Box 1" 

$groupBox2 = New-Object System.Windows.Forms.GroupBox 
$groupBox2.text = "Group Box 2" 

$form.controls.add($groupBox1) 
$form.controls.add($groupBox2) 

$form.showdialog() 

這樣做只能說明我的$groupBox1組框。任何幫助是極大的讚賞!

回答

3

您應該設置位置爲每個組框或使用某種表格佈局:

$form = New-Object System.Windows.Forms.Form 

$groupBox1 = New-Object System.Windows.Forms.GroupBox 
$groupBox1.text = "Group Box 1" 

$groupBox2 = New-Object System.Windows.Forms.GroupBox 
$groupBox2.text = "Group Box 2" 

$tableLayoutPanel1 = New-Object System.Windows.Forms.TableLayoutPanel 
$tableLayoutPanel1.RowCount = 2 

$tableLayoutPanel1.Controls.Add($groupBox1, 0, 0); 
$tableLayoutPanel1.Controls.Add($groupBox2, 0, 1); 
$tableLayoutPanel1.Dock = [System.Windows.Forms.DockStyle]::Fill 
$form.controls.add($tableLayoutPanel1) 

$form.showdialog() 
+0

有多個面板:https://msdn.microsoft.com/en-us/library/system.windows .forms.panel(v = vs.110).aspx它看起來像FlowLayoutPanel和SplitterPanel是可以用來回答這個問題的其他兩種類型,儘管還有其他類型的面板。 – Andrew

+0

On FlowLayoutPanel:https://docs.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-anchor-and-dock-child-controls-in-a-flowlayoutpanel-control – Andrew