Reputation: 962
I need to dynamically resize a form object when the form resizes. The user will drag and drop the edge of the form to resize it. I've been searching for the correct syntax to manage a form resize event in PowerShell, but have been unsuccessful.
Could someone tell me why resizeEnd
doesn't work on the form? Also, what the correct syntax would be to handle the resize event?
This is what I was attempting, but I kept getting errors:
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(1066,518)
$form.KeyPreview = $true
$form.StartPosition = "centerscreen"
$form.BackColor = "MidnightBlue"
$form.Add_KeyDown({
if($_.KeyCode -eq "Escape") {
$form.Close()
}
})
$form.Text = "Dialog Box 5.1"
$form.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($PSHOME + "\powershell_ise.exe")
$form.MinimumSize = New-Object System.Drawing.Size(1066,525)
#$form.SizeChanged({ $errorBox1.AppendText("resize") })
#$form.Resize({ Write-Host "resize" })
#$form.ClientSizeChanged({ Write-Host "size" })
$form.ResizeEnd({ Write-Host "resize" })
#$form.SizeChanged({ Write-Host "size" })
#$form.ControlAdded({ Write-Host "event" })
#$form.AutoSizeMode = New-Object System.Windows.Forms.AutoSizeMode
#$form.AutoSizeMode = "GrowAndShrink"
#$form.OnDragDrop({ Write-Host "drop" })
$form.ShowDialog() | Out-Null
Basically, I was trying to say, "If the form is resized write-host that the form was resized".
Upvotes: 3
Views: 6804
Reputation: 13176
Example:
$form.Add_Resize({
"form resized"
})
or
$resizeHandler = { "form resized" }
$form.Add_Resize( $resizeHandler )
Try this to see a long list of methods exposed by System.Windows.Forms.Form
:
$form = New-Object System.Windows.Forms.Form
$form | Get-Member -Force
Upvotes: 4