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.
This topic is 2 years and 5 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
fbhl_itdept
Posts: 1
Last visit: Thu Sep 29, 2022 9:46 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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/
This topic is 2 years and 5 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