Solved

Multiple radio button (2 groups) popup options with Powershell

Posted on 2009-04-12
3
6,539 Views
Last Modified: 2012-08-24
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?
[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()

Open in new window

0
Comment
Question by:Unisys1
  • 2
3 Comments
 

Author Comment

by:Unisys1
ID: 24127969
OK, I found the second part to my question, that was easy.  It's the first part I can't find an answer googling :-(
$RadioButton.checked = "True"

Open in new window

0
 

Accepted Solution

by:
Unisys1 earned 0 total points
ID: 24128111
Please bare with me as I am very new to Powershell, & Scripting in General, but It looks like I have found what I am looking for.  It was Groupbox.  Please review my code below and tell me where I may make improvements, but this is exactly what I was looking for.  
[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 = 250
$form.width = 375
 
# 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 = 20
$RadioButton.left = 5
$RadioButton.checked = "True"
 
# create radiobutton1
$radiobutton1 = New-Object Windows.Forms.radiobutton
$RadioButton1.text = "Button Text1"
$RadioButton1.height = 20
$RadioButton1.width = 150
$RadioButton1.top = 40
$RadioButton1.left =5
 
# create Groupbox
$GroupBox0 = New-Object Windows.Forms.GroupBox
$GroupBox0.Left = 10
$GroupBox0.Text = "1st Set"
$GroupBox0.Top = 42
$GroupBox0.Width = 160
$GroupBox0.Height = 100
$GroupBox0.Controls.Add($RadioButton)
$GroupBox0.Controls.Add($RadioButton1)
 
# create radiobutton
$RadioButton2 = New-Object Windows.Forms.radiobutton
$RadioButton2.text = "Button Text2"
$RadioButton2.height = 20
$RadioButton2.width = 160
$RadioButton2.top = 20
$RadioButton2.left = 5
$RadioButton2.checked = "True"
 
# create radiobutton2
$radiobutton3 = New-Object Windows.Forms.radiobutton
$RadioButton3.text = "Button Text3"
$RadioButton3.height = 20
$RadioButton3.width = 150
$RadioButton3.top = 40
$RadioButton3.left = 5
 
# create Groupbox
$GroupBox1 = New-Object Windows.Forms.GroupBox
$GroupBox1.Left = 180
$GroupBox1.Text = "2nd Set"
$GroupBox1.Top = 42
$GroupBox1.Width = 170
$GroupBox1.Height = 100
$GroupBox1.Controls.Add($RadioButton2)
$GroupBox1.Controls.Add($RadioButton3)
 
# create event handler for button
$event = {
if($radiobutton.checked){write-host "button pressed"}
if($radiobutton1.checked){write-host "button1 pressed"}
if($radiobutton2.checked){write-host "button2 pressed"}
if($radiobutton3.checked){write-host "button3 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 = 150
$button.left = 120
$form.controls.add($button)
 
 
# attach controls to form
$form.controls.add($Groupbox0)
$form.controls.add($Groupbox1)
$form.controls.add($button)
$form.controls.add($label)
$form.controls.add($textbox)
 
[VOID]$form.showdialog()

Open in new window

0
 

Expert Comment

by:garryshape
ID: 38329519
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.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This article will help you understand what HashTables are and how to use them in PowerShell.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now