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.
Locked
User avatar
RepublicSysEng
Posts: 5
Joined: Tue Nov 25, 2014 12:50 pm

Return to Parent Form

Post by RepublicSysEng » Tue Jan 13, 2015 3:10 pm

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
Joined: Wed Dec 03, 2014 2:26 pm

Return to Parent Form

Post by SAPIEN Support Forums » Tue Jan 13, 2015 3:10 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Return to Parent Form

Post by davidc » Tue Jan 13, 2015 4:39 pm

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.

User avatar
jvierra
Posts: 13807
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Return to Parent Form

Post by jvierra » Tue Jan 13, 2015 4:53 pm

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 7:12 am, edited 1 time in total.

User avatar
RepublicSysEng
Posts: 5
Joined: Tue Nov 25, 2014 12:50 pm

Re: Return to Parent Form

Post by RepublicSysEng » Wed Jan 14, 2015 6:40 am

@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!

User avatar
jvierra
Posts: 13807
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Return to Parent Form

Post by jvierra » Wed Jan 14, 2015 9:21 am

Check the rest of the blog posts on forms building and controls. They are very useful.

Locked