Form position size...

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
JMS_PT
Posts: 73
Last visit: Mon Sep 24, 2018 10:26 am

Form position size...

Post by JMS_PT »

I need to to set the Form`s position, size, etc.. when it loads
So far I can only get WindowState working using the $Form1_Shown = {} event, all others fail...

$Form1.Size.Width = $varFrmMSizeWidth
$Form1.Size.Height = $varFrmMSizeHeight
$Form1.Location.X = $varFrmMLocationX
$Form1.Location.Y = $varFrmMLocationY
$Form1.StartPosition = $varFrmMStartPosition
$Form1.WindowState = $varFrmMWindowState

These global variables are populated from an XML file when the form loads
Besides "WindowState" how to get all others working?
User avatar
JMS_PT
Posts: 73
Last visit: Mon Sep 24, 2018 10:26 am

Re: Form position size...

Post by JMS_PT »

Ok, found the solution here
viewtopic.php?t=1751

$Form1.Size = New-Object System.Drawing.Size ($varFrmMSizeWidth, $varFrmMSizeHeight)
$Form1.Location = New-Object System.Drawing.Point($varFrmMLocationX, $varFrmMLocationY)

Thank you.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Form position size...

Post by jvierra »

If you are using XML then you want to use strings to set values ... like this:

$form1.Size='400,600'
$form1.Location='50,100'

Also

$form1.StartPosition='CenterScreen'
User avatar
JMS_PT
Posts: 73
Last visit: Mon Sep 24, 2018 10:26 am

Re: Form position size...

Post by JMS_PT »

Thank you.
This topic is 8 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked