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
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
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