Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exiting Script

57 views
Skip to first unread message

Kryten

unread,
May 16, 2008, 9:22:19 AM5/16/08
to
Hi,

I have a script that builds a windows form ($form1) with several
buttons ($button1 ..$button6).
I want one of those buttons to stop script execution completely, just
like a 'quit' button doing
an "application.exit" -that kind of thing.

For some reason setting the button click event to 'Exit' doesn't seem
to work.

Any suggestions welcome.

Stuart

Marco Shaw [MVP]

unread,
May 16, 2008, 9:33:46 AM5/16/08
to

Here's a working example that is similar to what you're trying:

# Load the assembly since it isn't by default
[void][reflection.assembly]::loadwithpartialname("System.Windows.Forms")
# Create a top-level form
$form=new-object windows.forms.form
# Set the text property
$form.text="Hello World!"
# Create a button
$button=new-object windows.forms.button
# Set the text property
$button.text="Press me!"
# Add an event
$button.add_click({$form.close()})
# Add the button to the form
$form.controls.add($button)
# Make this active when shown
$form.add_shown({$form.activate()})
# Finally, show what we have!
$form.showdialog()

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com

Kryten

unread,
May 16, 2008, 11:54:25 AM5/16/08
to
Hi Marco,

11 Minutes for a spot on reply -what a job you guys do here!!

$form.Close() Does the trick just fine, I'm annoyed that I didn't
spot that method myself.

Thanks,

Stuart

0 new messages