Page 1 of 1

Popup Message Box to close form

Posted: Thu Aug 29, 2019 6:27 am
by bullitt773
How can I get the "ok" button on a popup box to close the form?



Product, version and build: 5.6.165
32 or 64 bit version of product: 64
Operating system:
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Re: Popup Message Box to close form

Posted: Thu Aug 29, 2019 7:28 am
by brittneyr
Add a click event to your "ok" button and in that event, use your form object to call the method Close(). For example:
  1. $form.Close()

Re: Popup Message Box to close form

Posted: Fri Aug 30, 2019 12:16 pm
by bullitt773
This is actually on a pop-up dialogue box:

Add-Type -AssemblyName "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
[void][System.Windows.Forms.MessageBox]::Show('mytext!', 'Attention!') # Casting the method to [void] suppresses the output.

Not sure where in this code to make this happen

Re: Popup Message Box to close form

Posted: Fri Aug 30, 2019 1:38 pm
by brittneyr
Well without any other context to what is your are trying to accomplish overall, if you want to close the form when the user hits ok on the messagebox, then you shouldn't be setting the output to void. Do something like the following:

Code: Select all

if('Ok' -eq [System.Windows.Forms.MessageBox]::Show("Message Text", "Title",'OKCancel')){
    write-host "You pressed OK"
    $form.Close()
}else{
    write-host "You pressed Cancel"
}