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.
User avatar
Posts: 1
Last visit: Mon Oct 18, 2021 9:00 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()?

Posts: 14987
Last visit: Tue Nov 30, 2021 11:26 pm
Answers: 15
Has voted: 3 times
Been upvoted: 12 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. ... logresult/