Form Closes on OK

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
DenverDenver
Posts: 19
Joined: Thu Nov 30, 2006 1:03 am

Form Closes on OK

Post by DenverDenver »

So, I feel quite silly asking but, I have no idea why when I hit OK button the form is closing.... below I added a 20 second delay at which point, the form closes.
On the properties of the form itself, the properties are like:
AcceptButton : none
CancelButton : buttonCancel

I would expect that the for remain open, even if I hit OK. The only code is:
  1. $buttonOK_Click = {
  2.  
  3.     Start-Sleep 20
  4.  
  5. }
It's been a while.. what am I missing?
powershell studio, current version 5.7.180 64 bit

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Form Closes on OK

Post by jvierra »

The buttons "DialogResult" is set to a value which causes the button to close the form.

User avatar
DenverDenver
Posts: 19
Joined: Thu Nov 30, 2006 1:03 am

Re: Form Closes on OK

Post by DenverDenver »

Thank you...
So on the ok button properties, "Dialogresult" is set to "OK"
That would make the form close?

User avatar
DenverDenver
Posts: 19
Joined: Thu Nov 30, 2006 1:03 am

Re: Form Closes on OK

Post by DenverDenver »

Indeed, changing it to 'none' stopped the behavior. Thanks! But honestly I don't get what that property does in this case. Any quick pointers?

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Form Closes on OK

Post by jvierra »

If you read the documentation for the control it will explain how the control works. The docs are always available by right-clicking the control in the toolbox.

User avatar
DenverDenver
Posts: 19
Joined: Thu Nov 30, 2006 1:03 am

Re: Form Closes on OK

Post by DenverDenver »

heh... RTFM.
Fair enough and thanks again for the help!

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Form Closes on OK

Post by jvierra »

I wanted to show you that the details and examples are only a click away. You will have many more issues that will be most easily solved by right-clicking on the control. The details are deep and my rewriting them will not be helpful if you do not understand the whole description of a control. Also it saves you time if you have the power to discover a mouse-click away.

The manual is not really a reference but a full class in the whole. It takes time and concentration to read a manual.
Here is a good manual to help gain a deep understanding of PowerShell. The part on forms is an excellent launch into forms building but depends on the parts of the manual that preface that chapter. The book is a free download.

Windows PowerShell™ 4: TFM

User avatar
Alexander Riedel
Posts: 7556
Joined: Tue May 29, 2007 4:43 pm
Answers: 1
Been upvoted: 4 times

Re: Form Closes on OK

Post by Alexander Riedel »

Also, there might be something on the blog about any given topic: https://www.sapien.com/blog/2015/06/29/ ... e-my-form/
Alexander Riedel
SAPIEN Technologies, Inc.

jvierra
Posts: 14667
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: Form Closes on OK

Post by jvierra »

Alex - blog posts would be most useful if they were linked to the SpotLight articles.

User avatar
Alexander Riedel
Posts: 7556
Joined: Tue May 29, 2007 4:43 pm
Answers: 1
Been upvoted: 4 times

Re: Form Closes on OK

Post by Alexander Riedel »

Yeah, I know. If I find someone who isn't looking busy at the moment I'll get them on that :D
Alexander Riedel
SAPIEN Technologies, Inc.

Locked