Change formsize with button action

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 1 year and 11 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
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Change formsize with button action

Post by lontru »

Hi

How do i change the form size from a button press.

The form is 300,300

want to press a button and change the Height to 400 but nothing happen when i click?

$button1_Click={
#TODO: Place custom script here
$form1.Size.Height = "400"
}
User avatar
lontru
Posts: 103
Last visit: Thu Mar 07, 2024 2:00 pm

Re: Change formsize with button action

Post by lontru »

found the way

viewtopic.php?t=1751

Code: Select all

$button1_Click={
	#TODO: Place custom script here
	if ($form1.Size.Height -eq 400) {
		$height = 300
	}
	else
	{
		$height = 400
	}
	$width = $form1.Size.Width
	
	$form1.Size = New-Object System.Drawing.Size ($width, $height)
}
mark as solved.
This topic is 1 year and 11 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