I've written a Powershell GUI script, and it does everything I want, but when I finished it, I have noticed that when I drag the right bottom corner of the window to make the window bigger, the buttons stay in the same position, while the window it self becomes bigger. So something like this:
Add-Type -assembly System.Windows.Forms
$searchForm = New-Object System.Windows.Forms.Form
$searchForm.Size = New-Object System.Drawing.Size(200, 200)
$searchForm.AutoSize = $true
$searchForm.AutoScale = $true
$CANCELButton = New-Object System.Windows.Forms.Button
$CANCELButton.Location = New-Object System.Drawing.Size(150, 120)
$CANCELButton.Size = New-Object System.Drawing.Size(120, 30)
$CANCELButton.Text = "CANCEL"
$CANCELButton.Add_Click({$searchForm.Close()})
$searchForm.Controls.Add($CANCELButton)
$searchForm.ShowDialog()
After searching online I've found the "Anchor", which does exactly what I want. Something like this:
Add-Type -assembly System.Windows.Forms
$searchForm = New-Object System.Windows.Forms.Form
$searchForm.Size = New-Object System.Drawing.Size(200, 200)
$searchForm.AutoSize = $true
$searchForm.AutoScale = $true
$CANCELButton = New-Object System.Windows.Forms.Button
$CANCELButton.Location = New-Object System.Drawing.Size(150, 120)
$CANCELButton.Size = New-Object System.Drawing.Size(120, 30)
$CANCELButton.Text = "CANCEL"
$CANCELButton.Add_Click({$searchForm.Close()})
$searchForm.Controls.Add($CANCELButton)
$CANCELButton.Anchor = "Bottom,Right"
$searchForm.ShowDialog()
And it technically does what I want.Now when I drag the bottom right corner of the window to make it bigger, the button goes with it, but when I try to make the window smaller the button doesn't seem to allow me to reduce size of the window, but it stays in the position where it moved and it's like "anchored" on the position on the screen. Any solutions for this?
Thanks in advance.