Unisys1
asked on
Multiple radio button (2 groups) popup options with Powershell
I need help with a powershell script. I am missing 2 features that I cannot figure how to write. On 1 popup form, I'd like (using radio buttons) two sets of choices and have them spit out 2 variables. Like this:
Choice 1:
Blue
Green
Red
Choice 2:
Car
Truck
Motorcycle
Results:
Blue Car
My code below will create 1 set of options, now how do I create a second set? Finally, I'd also like to have a default options radio button selected, any help? Like set the default radio to Car & blue?
Choice 1:
Blue
Green
Red
Choice 2:
Car
Truck
Motorcycle
Results:
Blue Car
My code below will create 1 set of options, now how do I create a second set? Finally, I'd also like to have a default options radio button selected, any help? Like set the default radio to Car & blue?
[VOID][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
# create form
$form = New-Object Windows.Forms.Form
$form.text = "What do you want to do?"
$form.top = 10
$form.left = 10
$form.height = 130
$form.width = 275
# create label
$label = New-Object Windows.Forms.Label
$label.text = "Select a button"
$label.height = 30
$label.width = 75
$label.top = 2
$label.left = 25
$form.controls.add($label)
# create radiobutton
$RadioButton = New-Object Windows.Forms.radiobutton
$RadioButton.text = "Button Text"
$RadioButton.height = 20
$RadioButton.width = 150
$RadioButton.top = 2
$RadioButton.left = 100
$form.controls.add($RadioButton)
# create radiobutton1
$radiobutton1 = New-Object Windows.Forms.radiobutton
$RadioButton1.text = "Button Text1"
$RadioButton1.height = 20
$RadioButton1.width = 150
$RadioButton1.top = 30
$RadioButton1.left =100
$form.controls.add($RadioButton1)
# create event handler for button
$event = {
if($radiobutton.checked){write-host "button pressed"}
if($radiobutton1.checked){write-host "button1 pressed"}
$form.Close()
}
# create button
$button = New-Object Windows.Forms.Button
$button.Add_Click($event)
$button.text = "OK"
$button.height = 20
$button.width = 50
$button.top = 60
$button.left = 100
$form.controls.add($button)
# attach controls to form
$form.controls.add($button)
$form.controls.add($label)
$form.controls.add($textbox)
[VOID]$form.showdialog()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for self-posting resolution.
So that worked for you, right? I'm about to try radio button on my script and want to make sure I get it right.
So that worked for you, right? I'm about to try radio button on my script and want to make sure I get it right.
ASKER
Open in new window