Hello,
I am in need of some assistance with the below form. I am attempting to write the response of the button selection to $LogonPrompt, however the variable does not exist after running the function.
Any help would be greatly appreciated!
# A function to create the form
function Prompt_Logon{
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')
# Set the size of the form
$Form = New-Object System.Windows.Forms.Form
$Form.width = 500
$Form.height = 400
$Form.Text = 'GUI Logon Type'
# Set the font of the text to be used within the form
$Font = New-Object System.Drawing.Font('Times New Roman',12)
$Form.Font = $Font
# Create a group that will contain the radio buttons
$MyGroupBox = New-Object System.Windows.Forms.GroupBox
$MyGroupBox.Location = '40,30'
$MyGroupBox.size = '400,240'
$MyGroupBox.text = 'Select Logon'
# Create the collection of radio buttons
$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location = '20,40'
$RadioButton1.size = '350,20'
$RadioButton1.Checked = $true
$RadioButton1.Text = 'Project Accounting'
$RadioButton2 = New-Object System.Windows.Forms.RadioButton
$RadioButton2.Location = '20,70'
$RadioButton2.size = '350,20'
$RadioButton2.Checked = $false
$RadioButton2.Text = 'Finance'
$RadioButton3 = New-Object System.Windows.Forms.RadioButton
$RadioButton3.Location = '20,100'
$RadioButton3.size = '350,20'
$RadioButton3.Checked = $false
$RadioButton3.Text = 'Order Management'
$RadioButton4 = New-Object System.Windows.Forms.RadioButton
$RadioButton4.Location = '20,130'
$RadioButton4.size = '350,20'
$RadioButton4.Checked = $false
$RadioButton4.Text = 'Purchasing - Receiving'
$RadioButton5 = New-Object System.Windows.Forms.RadioButton
$RadioButton5.Location = '20,160'
$RadioButton5.size = '350,20'
$RadioButton5.Checked = $false
$RadioButton5.Text = 'Japan'
$RadioButton6 = New-Object System.Windows.Forms.RadioButton
$RadioButton6.Location = '20,190'
$RadioButton6.size = '350,20'
$RadioButton6.Checked = $false
$RadioButton6.Text = 'None'
# Add an OK button
$OKButton = new-object System.Windows.Forms.Button
$OKButton.Location = '130,280'
$OKButton.Size = '100,40'
$OKButton.Text = 'OK'
$OKButton.DialogResult=[System.Windows.Forms.DialogResult]::OK
#Add a Cancel button
$CancelButton = new-object System.Windows.Forms.Button
$CancelButton.Location = '255,280'
$CancelButton.Size = '100,40'
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult=[System.Windows.Forms.DialogResult]::Cancel
# Add all the Form controls on one line
$form.Controls.AddRange(@($MyGroupBox,$OKButton,$CancelButton))
# Add all the GroupBox controls on one line
$MyGroupBox.Controls.AddRange(@($Radiobutton1,$RadioButton2,$RadioButton3,$RadioButton4,$RadioButton5,$RadioButton6))
# Assign the Accept and Cancel options in the form to the corresponding buttons
$form.AcceptButton = $OKButton
$form.CancelButton = $CancelButton
# Activate the form
$form.Add_Shown({$form.Activate()})
# Get the results from the button click
$dialogResult = $form.ShowDialog()
# If the OK button is selected
if ($dialogResult -eq 'OK'){
# Check the current state of each radio button and respond accordingly
if ($RadioButton1.Checked -eq $true){
$LogonPrompt='1_Project Accounting'}
elseif ($RadioButton2.Checked -eq $true){
$LogonPrompt='2_Finance'}
elseif ($RadioButton3.Checked -eq $true){
$LogonPrompt='3_Order Management'}
elseif ($RadioButton4.Checked -eq $true){
$LogonPrompt='4_Purchasing_Receiving'}
elseif ($RadioButton5.Checked -eq $true){
$LogonPrompt='5_Japan'}
elseif ($RadioButton6.Checked -eq $true){
$LogonPrompt='6_None'}
}
}
# Call the function
Prompt_Logon