Closing a form in code

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 5 years and 10 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
chris.hartmann@braunability.com
Posts: 4
Last visit: Mon Dec 04, 2023 8:18 am

Closing a form in code

Post by chris.hartmann@braunability.com »

How do you close a form in code?
I want a process to run when the form opens and when it is finished have it close and I just can't figure out how to do it.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Closing a form in code

Post by jvierra »

$form.Close()
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Closing a form in code

Post by mxtrinidad »

Use $MainForm.Close() or name of the form with *.close().

$NameOfTheForm.Close()

Code: Select all

$buttonCallChildForm_Click={
	#TODO: Place custom script here
	if((Show-ChildForm_psf) -eq 'OK')
	{
		
	}
	## - sample of closing main form after working with the Childform:
	$MainForm.Close()
}

:)
This topic is 5 years and 10 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