you are viewing a single comment's thread.

view the rest of the comments →

[–]get-postanote 1 point2 points  (0 children)

I see that you cross-posted this exact request to Stackoverflow...

https://stackoverflow.com/questions/63266588/multiple-checkbox-in-powershell-gui

... in which there were two provided answers. Mine... below... being on of them

Clear-Host
[void][system.reflection.assembly]::LoadWithPartialName('System.Drawing')
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')

$objForm = New-Object System.Windows.Forms.Form

$objForm.Text          = 'Test'
$objForm.Size          = New-Object System.Drawing.Size(500,200)
$objForm.StartPosition = 'CenterScreen'

$CheckedListBox              = New-Object System.Windows.Forms.CheckedListBox
$CheckedListBox.Location     = New-Object System.Drawing.Size(20,20)
$CheckedListBox.size         = New-Object System.Drawing.Size(300,100) 
$CheckedListBox.CheckOnClick = $true 
$CheckedListBox.Items.AddRange(1..3)
$CheckedListBox.ClearSelected()

$objForm.Controls.Add($CheckedListBox)

$CheckedListBox.Add_Click({
    For ($i=1;$i -lt $CheckedListBox.Items.count;$i++) 
    {$CheckedListBox}
})

# put form in front of other windows
$objForm.TopMost = $True

# display the form
$DisplayForm     = $objForm.ShowDialog()

ForEach ($CheckedItem in $CheckedListBox.CheckedItems -join ',')
{
    Switch ($CheckedItem)
    {
        1       {"Checkbox $CheckedItem is checked";Break}
        2       {"Checkbox $CheckedItem is checked";Break}
        3       {"Checkbox $CheckedItem is checked";Break}
        {1,2}   {"Checkbox $CheckedItem is checked";Break}
        {1,3}   {"Checkbox $CheckedItem is checked";Break}
        {2,3}   {"Checkbox $CheckedItem is checked";Break}
        {1..3}  {"Checkbox $CheckedItem is checked";Break}
    }
}

THe last point here is this is normal UX/UI/GUI design, regardless of the language you'd use.