Learn about Windows PowerShell
Summary: Learn to use the OK and Cancel buttons in a Windows PowerShell GUI.
How can I use Windows PowerShell to get my GUI’s OK and Cancel buttons to trigger when the user presses ENTER or Escape?
Assign the OK and Cancel button objects to your form’s AcceptButton and CancelButton properties:
$form.AcceptButton = $OKButton$form.CancelButton = $CancelButton
$button1.DialogResult = 'Cancel'
$buttonOK.DialogResult = 'OK'
The "DialogResult" can take these values and all will terminate the form and return the enum value.
Yep! Assigning values to the DialogResult properties is mentioned in the main article (
http://blogs.technet.com/b/heyscriptingguy/archive/2014/08/02/weekend-scripter-fixing-powershell-gui-examples.aspx ), but not in the PowerTip.
Please check my article at codeproject for extensive coverage of using Windows Forms and WPF with Powershell for
typical Powershell tasks which often require various option prompts.
Many common Windows form patterns are covered there to create user-friendly
The daily devops tasks of running Powershell in a complex environment become a less challenging task
Code for all samples is provided.