我想在我的GUI表单中创建一个组框。我对窗体使用最大化的windowsState。我想使用分组框,并且需要使分组框也最大化,但要结合边距和填充。因此,即使分辨率屏幕更改,组框的大小和位置也不会更改。
我试过了,但是没有用。
任何人都可以帮助我。谢谢。

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.text                       = "Form"
$Form.TopMost                    = $false
$Form.FormBorderStyle            = "FixedDialog"
$Form.MaximizeBox                = $false
$Form.startposition              = "centerscreen"
$Form.WindowState                = 'Maximized'


$Groupbox1                       = New-Object system.Windows.Forms.Groupbox
$Groupbox1.text                  = "Group Box"
$Groupbox1.location              = New-Object System.Drawing.Point(8,13)
$Groupbox1.Padding               = New-Object -TypeName System.Windows.Forms.Padding -ArgumentList (0,5,5,0)
$Groupbox1.Margin                = 2,2,2,2

$Form.controls.AddRange(@($Groupbox1))
[void]$Form.ShowDialog()

最佳答案

您必须首先创建宽度和高度均为100%的面板。然后将groupbox放在面板中,这应该可以工作:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.text                       = "Form"
$Form.TopMost                    = $false
$Form.FormBorderStyle            = "FixedDialog"
$Form.MaximizeBox                = $false
$Form.startposition              = "centerscreen"
$Form.WindowState                = 'Maximized'

$Panel = New-Object System.Windows.Forms.TableLayoutPanel
$panel.Dock = "Fill"
$panel.ColumnCount = 1
$panel.RowCount = 1
$panel.CellBorderStyle = "single"
$panel.ColumnStyles.Add((new-object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Percent, 100)))
$panel.RowStyles.Add((new-object System.Windows.Forms.RowStyle([System.Windows.Forms.SizeType]::Percent, 100)))

$Groupbox1                       = New-Object system.Windows.Forms.Groupbox
$Groupbox1.text                  = "Group Box"
$Groupbox1.location              = New-Object System.Drawing.Point(8,13)
$Groupbox1.Padding               = New-Object -TypeName System.Windows.Forms.Padding -ArgumentList (0,5,5,0)
$Groupbox1.Dock                  = "fill"

$form.controls.add($Panel)
$panel.controls.AddRange(@($Groupbox1))
[void]$Form.ShowDialog()

关于powershell - 如何在PowerShell中使用GUI使用最大化组框?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59082581/

10-12 03:52