Forms PowerShell CheckedListBox一次只能选择一个选项

Forms PowerShell CheckedListBox一次只能选择一个选项,forms,powershell,checklistbox,Forms,Powershell,Checklistbox,我有一个PowerShell表单,它包含一个“System.Windows.Forms.CheckedListBox”对象。目前,我可以一次选择多个复选框选项: 是否有一种简单的方法使选中列表框只允许一个选择 或者我必须在脚本中使用一些'onClick'事件逻辑吗 检查列表框蛋白质: $checkedlistbox2.BackColor = 'Control' $checkedlistbox2.BorderStyle = 'None' $checkedlistbox2.CheckOnClic

我有一个PowerShell表单,它包含一个
“System.Windows.Forms.CheckedListBox”
对象。目前,我可以一次选择多个复选框选项:

是否有一种简单的方法使
选中列表框
只允许一个选择

或者我必须在脚本中使用一些
'onClick'
事件逻辑吗

检查列表框蛋白质:

$checkedlistbox2.BackColor = 'Control'
$checkedlistbox2.BorderStyle = 'None'
$checkedlistbox2.CheckOnClick = $True
$checkedlistbox2.ColumnWidth = 56
$checkedlistbox2.FormattingEnabled = $True
[void]$checkedlistbox2.Items.Add("W2K")
[void]$checkedlistbox2.Items.Add("WXP")
[void]$checkedlistbox2.Items.Add("WS7")
$checkedlistbox2.Location = '107, 284'
$checkedlistbox2.MultiColumn = $True
$checkedlistbox2.Name = "checkedlistbox2"
$checkedlistbox2.SelectionMode = 'None'
$checkedlistbox2.Size = '192, 15'
$checkedlistbox2.TabIndex = 66

您是否尝试将SelectionMode属性更改为“一”

或者,您可以使用单选按钮控件,一次只允许一个选择?大概是这样的:

$radioButton1 = New-Object System.Windows.Forms.RadioButton
$radioButton2 = New-Object System.Windows.Forms.RadioButton
$radioButton1.Checked = $True
$radioButton1.Name = "W2K"
$radioButton1.Text = "W2K"
$radioButton1.Location = New-Object System.Drawing.Point(10,10)
$radioButton2.Name = "WXP"
$radioButton2.Text = "WXP"
$radioButton2.Location = New-Object System.Drawing.Point(10,30)
$form.Panel1.Controls.Add($radioButton1)
$form.Panel1.Controls.Add($radioButton2)

我尝试了
SelectionMode=“One”
,但这不起作用。单选按钮是个好主意。您知道如何在同一表单中设置两组单选按钮组(两组仅允许一个选择)?同一父项中的单选按钮将自动分组。因此,如果您将这两个组放置在两个不同的面板容器中,就可以了。还有GroupBox控件,但它会在组周围绘制边框<代码>$groupBox=新对象系统.Windows.Forms.groupBox
$radioButton1 = New-Object System.Windows.Forms.RadioButton
$radioButton2 = New-Object System.Windows.Forms.RadioButton
$radioButton1.Checked = $True
$radioButton1.Name = "W2K"
$radioButton1.Text = "W2K"
$radioButton1.Location = New-Object System.Drawing.Point(10,10)
$radioButton2.Name = "WXP"
$radioButton2.Text = "WXP"
$radioButton2.Location = New-Object System.Drawing.Point(10,30)
$form.Panel1.Controls.Add($radioButton1)
$form.Panel1.Controls.Add($radioButton2)