Page 1 of 1

Form ExitButton (X) action

Posted: Sat Sep 01, 2018 3:51 pm
by laned101
Im running input validation checks on FormClosing event, this means if I try close the form via the Exit button (top right) I hit validation issues. Is there a way to check if the X button has been clicked to bypass the validation on Exit button click?

Re: Form ExitButton (X) action

Posted: Sat Sep 01, 2018 3:55 pm
by jvierra
Remove the control box from the form.

Re: Form ExitButton (X) action

Posted: Sat Sep 01, 2018 5:18 pm
by laned101
Then I wont be able to close the form unless I complete all fields. Is there a way to check if any button has been clicked? Surely there must be a bool somewhere?

I tried defining a bool variable in GLobals then setting it to true in th OKButtonclick event but when querying it in the closing event it reads incorrectly.

Re: Form ExitButton (X) action

Posted: Sat Sep 01, 2018 5:22 pm
by jvierra
I posted an example of how to close and cancel a form. You cannot detect if the "X" has been clicked. The code posted shows you how to deal with the closing issue. If you need something else then you will have to learn how forms work and ask a better question.

You can set a variable in any event and that will be visible anywhere in the form and in any event. You have to "scope" the variable when assigning it or the change will be lost when the event exits.

Re: Form ExitButton (X) action

Posted: Sun Sep 02, 2018 2:15 am
by laned101
So I'm keeping the exit button, I just defined the scope for the variable in Globals and its working as expected now.

Although your comments are a little dismissing and presumptuous I do appreciate the help. A ref to your "post" would have been useful however, the mention of scope was in fact useful. Thank you

Re: Form ExitButton (X) action

Posted: Sun Sep 02, 2018 2:43 am
by jvierra
I attached a full example for everything you asked in the beginning. I couldn't understand why you kept asking the same question after I had answered it three different ways.

Without a good understanding of PowerShell basics using form will be a challenge. Also look at the articles and examples in the info center to get a better idea of how forms work.

Re: Form ExitButton (X) action

Posted: Sun Sep 02, 2018 11:42 am
by laned101
Yes I'm not familiar with forms, but I have some experience in Powershell but mostly python, Ive resolved the problem nonetheless. I wanted to keep the control box and as this is the first form Ive ever created I wasn't sure on the best location to carry things like validation but now I know the flow a bit better, and understand the event triggers (im new to GUIs in generally, always been a terminal guy) Ive setup input validation on all fields (multiple child forms), setup local logging and error output, terminal logging (gui). I will setup a SYSLOG function on specific events next. Thanks again

Re: Form ExitButton (X) action

Posted: Sun Sep 02, 2018 11:48 am
by jvierra
So then you understand that you cannot detect that the "X" has been clicked. You can only detect a button click and use that to eliminate the issue?