Return to Parent Form

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 9 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
RepublicSysEng
Posts: 5
Last visit: Mon Nov 26, 2018 6:45 pm

Return to Parent Form

Post by RepublicSysEng »

I have created a main form that takes user inputs and when they click a button it validates all children. If validation is successful it opens a child form. My problem is when I close the child it also closes the parent, which is what I don't want. I want to return to the parent form. I'm assuming the reason is that when the users presses the button it's set for 'OK' and the validation runs when the form is closing. So as the main form closes it pops up the child form. And when the child closes the program exits because the parent was in a closing state.

I'm using global variables to pass information. Do I need to put information in return variables so the parent doesn't close? Do I need to run validation some other way and call the child form?

I'm missing something, but I'm not sure what.
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Return to Parent Form

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, RepublicSysEng.

Did you remember to include the following?
  • 1. Product, version and build (e.g. Product: PowerShell Studio 2014, Version & Build: 4.1.71. Version and build information can be found in the product's About box accessed by clicking the blue icon with the 'i' in the upper right hand corner of the ribbon.)
    2. Specify if you are running a 32 or 64 bit version
    3. Specify your operating system and if it is 32 or 64 bit.
    4. Attach a screenshot if your issue can be seen on the screen
    5. Attach a zip file if you have multiple files (crash reports, log entries, etc.) related to your issue.
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Return to Parent Form

Post by davidc »

Moved this post to the PowerShell GUIs forum.

Please include sample code as to how you call the child form and validate.

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

Re: Return to Parent Form

Post by jvierra »

A simple thing to prevent a form from closing in the close event.

$_.Cancel=$true

This will cancel the close event and the form will stay visible. Processing will continue until the next close event. To close the form you must, at some point, not cancel the event.
Last edited by jvierra on Wed Jan 14, 2015 6:12 am, edited 1 time in total.
User avatar
RepublicSysEng
Posts: 5
Last visit: Mon Nov 26, 2018 6:45 pm

Re: Return to Parent Form

Post by RepublicSysEng »

@jvierra
That is exactly what I needed. Thank you very much. Still learning about the GUI end, obviously. I see that was pointed out in a couple of articles, but I didn't think of setting that again to keep the form open. I really appreciate the help!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Return to Parent Form

Post by jvierra »

Check the rest of the blog posts on forms building and controls. They are very useful.
This topic is 9 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