Popup Message Box to close form

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
bullitt773
Posts: 8
Joined: Tue Jul 02, 2019 6:02 pm

Popup Message Box to close form

Post by bullitt773 » Thu Aug 29, 2019 6:27 am

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

User avatar
brittneyr
Site Admin
Posts: 162
Joined: Thu Jun 01, 2017 7:20 am

Re: Popup Message Box to close form

Post by brittneyr » Thu Aug 29, 2019 7:28 am

Add a click event to your "ok" button and in that event, use your form object to call the method Close(). For example:

Code: Select all

$form.Close()
Brittney Ryn
SAPIEN Technologies, Inc.

bullitt773
Posts: 8
Joined: Tue Jul 02, 2019 6:02 pm

Re: Popup Message Box to close form

Post by bullitt773 » Fri Aug 30, 2019 12:16 pm

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

User avatar
brittneyr
Site Admin
Posts: 162
Joined: Thu Jun 01, 2017 7:20 am

Re: Popup Message Box to close form

Post by brittneyr » Fri Aug 30, 2019 1:38 pm

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"
}
Brittney Ryn
SAPIEN Technologies, Inc.