Clear Fields or Not Submit Data on Form Close

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.
Post Reply
User avatar
fbhl_itdept
Posts: 1
Last visit: Tue Oct 12, 2021 9:02 am

Clear Fields or Not Submit Data on Form Close

Post by fbhl_itdept »

I'm working on a toolbox app for our IT department and one of the functions used all the time is New User Creation. In our project it opens a second form, aduserForm.psf, with all the fields listed. What I'm trying to do is clear the fields when the form is closed by not using Submit (so using the Form Control X button), or just not send the field data back to the main form if Submit is not used.

Is there a way to make that distinction for form.close()?

jvierra
Posts: 14946
Last visit: Tue Oct 12, 2021 10:31 am
Answers: 14
Has voted: 3 times
Been upvoted: 11 times

Re: Clear Fields or Not Submit Data on Form Close

Post by jvierra »

There is no "Submit" button on a form. You are thinking of HTML forms. PowerShell Studio WinForms always lose all data when closed. Re-opening a form will have it open with whatever defaults have been set in the form.

WinForms do not send data back to the calling form. In PSS the forms controls are made available to the calling form as special variables. If you want those variables to be cleared then you will have to write code to do that. There is no automatic way to do that.

WHen a "Dialog" closes the close method can set the "DialogResult" which is returned as the result of the function that opened the form. This value will tell you what kind close was intended.

See the following as a place to start.
https://www.sapien.com/blog/2015/12/23/ ... logresult/

Post Reply