Multi-Form "Close current form" script

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 7 years and 4 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
Marcboi
Posts: 7
Last visit: Mon Dec 19, 2016 4:41 am

Multi-Form "Close current form" script

Post by Marcboi »

Hi guys,
I am currently working on a Multi-Form project with PowerShell Studio 2016 and am looking into having multiple form connections.
I would want the current active form to close once the linked form is opened.
For example:
1. I click on the AD Account Setup from my "MainForm.psf".
2. The "AD Account Setup.psf" form opens and the "MainForm.psf" closes.

I've searched the forums but cannot seem to find anything related to this exact behavior.

Thanks in advance for the tips
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form "Close current form" script

Post by jvierra »

That cannot be done with PowerShell as all forms are modal dialogs. A parent form cannot close when it is displaying a child form.
User avatar
Marcboi
Posts: 7
Last visit: Mon Dec 19, 2016 4:41 am

Re: Multi-Form "Close current form" script

Post by Marcboi »

Is there any way I could Hide it?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form "Close current form" script

Post by jvierra »

Hiding the form will close it and the child form.

PowerShell does not use Modeless forms. It uses only modal dialogs.

I recommend using tabs or panels to change the display. Using panels you can change the contents of a form and it can hide the previous contents.
User avatar
Marcboi
Posts: 7
Last visit: Mon Dec 19, 2016 4:41 am

Re: Multi-Form "Close current form" script

Post by Marcboi »

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: Multi-Form "Close current form" script

Post by jvierra »

You are welcome.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Multi-Form "Close current form" script

Post by Lembasts »

I was just about to ask the same question.
I'm creating a 'Wizard' type project which displays several forms one after the other.
It appears that I cannot close the parent when calling the child so I'll live with that.
However, If I'm on, say, my fifth wizard form and they press Exit, can I close all child forms and the original parent form at once?
Thanks
David
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form "Close current form" script

Post by jvierra »

Use a tab that is designed to do this.

There is a form template for a wizard called "Wizard Template" and it does all of what you are trying to do.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: Multi-Form "Close current form" script

Post by Lembasts »

Thanks - I was stuck in the old multi form wizard way of thinking.
I just had a look at the Wizard template and it looks cool and appears to do everything I need.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Multi-Form "Close current form" script

Post by jvierra »

Well it will be able to get you closer and it uses a pretty stock wizard approach.
This topic is 7 years and 4 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