PowerShell检查选中了哪个动态创建的单选按钮

时间:2019-10-23 02:44:07

标签: powershell radio-button

这是我的代码。 创建这样的单选按钮后,我很难找到一种确定方法。

$locationY = [int]10
foreach($type in $labels){
    # Create the collection of radio buttons
    $RadioButton = New-Object System.Windows.Forms.RadioButton
    $RadioButton.Location = "20,$(30+$locationY)"
    $RadioButton.size = '350,20'
    if($type -eq 'Chrysler'){$RadioButton.Checked = $true}else{$RadioButton.Checked = $false}
    $RadioButton.Text = $type  
    $RadioButton.Name = $type 
    $Form.Controls.Add($RadioButton)
}

1 个答案:

答案 0 :(得分:1)

您可以在此处使用GroupBox,然后从如下所示的组框中查看选中了哪个。

# code to define groupbox control

$locationY = [int]10
foreach($type in $labels){
    # Create the collection of radio buttons
    $RadioButton = New-Object System.Windows.Forms.RadioButton
    $RadioButton.Location = "20,$(30+$locationY)"
    $RadioButton.size = '350,20'
    if($type -eq 'Chrysler'){$RadioButton.Checked = $true}else{$RadioButton.Checked = $false}
    $RadioButton.Text = $type  
    $RadioButton.Name = $type 
    $Form.Controls.Add($RadioButton)
    $GroupBox.Controls.Add($RadioButton)
}

$ClickedRadioButton = $GroupBox.Controls | Where-Object -FilterScript {$_.Checked}