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 LICENSE NUMBERS, ACTIVATION 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.
This topic is 4 years and 6 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.
bullitt773
Posts: 12
Last visit: Wed Mar 06, 2024 5:29 am

Popup Message Box to close form

Post 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
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 3:14 pm
Answers: 39
Been upvoted: 30 times

Re: Popup Message Box to close form

Post 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()
Brittney
SAPIEN Technologies, Inc.
bullitt773
Posts: 12
Last visit: Wed Mar 06, 2024 5:29 am

Re: Popup Message Box to close form

Post 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
User avatar
brittneyr
Site Admin
Posts: 1655
Last visit: Thu Mar 28, 2024 3:14 pm
Answers: 39
Been upvoted: 30 times

Re: Popup Message Box to close form

Post 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"
}
Brittney
SAPIEN Technologies, Inc.
This topic is 4 years and 6 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.