troubleshooting Question

Powershell form - Anchor a button to a dynamically sized groupbox

Avatar of Richard Gardner
Richard GardnerFlag for United Kingdom of Great Britain and Northern Ireland asked on
.NET ProgrammingPowershell
2 Comments1 Solution2552 ViewsLast Modified:
I have a Powershell form with a dynamically sized groupbox (GrowOnly).

Can anyone tell me  how to anchor a button to the bottom of the group box?

Alternatively, how can I anchor the button so it is always at the bottom of the form? (the button is basically a close form button)

Here is a basic form I was using to practice on -

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$Form = New-Object System.Windows.Forms.Form    
$Form.Size = New-Object System.Drawing.Size(900,700)
$Form.WindowState = "Normal"
$Form.StartPosition = "CenterScreen"
$Form.AutoSizeMode = "GrowAndShrink"

$GroupBox1x = 10
$GroupBox1 = New-Object System.Windows.Forms.GroupBox
$GroupBox1.Location = New-Object System.Drawing.Size($GroupBox1x,0)
$GroupBox1.Size = New-Object System.Drawing.Size @(700,30)
$GroupBox1.AutoSize = $true
$GroupBox1.AutoSizeMode = "GrowOnly"
$GroupBox1.Text = "Group Box 1"

$Labelx = 10
$labely = 30
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Location = New-Object System.Drawing.Size($Labelx,$labely)
$Label1.Text = "Test1"
$Label1.Size = New-Object System.Drawing.Size(85,15)

$labely += 20
$Label2 = New-Object System.Windows.Forms.Label
$Label2.Location = New-Object System.Drawing.Size($Labelx,$labely)
$Label2.Text = "Test 2"
$Label2.Size = New-Object System.Drawing.Size(85,15)

$ButtonRestart = New-Object System.Windows.Forms.Button
$ButtonRestart.Size = New-Object System.Drawing.Size(70,30)
$ButtonRestart.Text = "Restart"
$ButtonRestart.Add_Click({funcRestart})

$Form.Controls.Add($GroupBox1)
$GroupBox1.Controls.Add($Label1)
$GroupBox1.Controls.Add($Label2)
$Form.Controls.Add($ButtonRestart)

$Form.ShowDialog() | Out-Null
ASKER CERTIFIED SOLUTION
Coralon
Senior Citrix Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros