# Powershell Checkboxes

**URL:** <https://forums.powershell.org/t/powershell-checkboxes/21275>\
**Category:** PowerShell Help\
**Created:** [January 4, 2023, 9:29am UTC](https://forums.powershell.org/t/powershell-checkboxes/21275 "2023-01-04T09:29:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KochiThelyx](https://avatars.discourse-cdn.com/v4/letter/k/8e8cbc/32.png) [@KochiThelyx](https://forums.powershell.org/u/KochiThelyx)\
**Post date:** [January 4, 2023, 9:29am UTC](https://forums.powershell.org/t/powershell-checkboxes/21275/1 "2023-01-04T09:29:07Z")

</div>

To make it short, i just want a button to appear (enable) when i hit all 3 checkboxes.

i wrote this mess together but it works pretty bad ( only enables when checked in order and doesnt uncheck when i uncheck some of them)

$checkbox1.add\_checkstatechanged -and $checkbox2.add\_checkstatechanged -and $checkbox3.add\_checkstatechanged ({  
if($checkbox1.checked -and $checkbox2.checked -and $checkbox3.checked)  
{$button.enabled = $true }  
else {  
$button.enabled = %false }})

Thanks !

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [January 4, 2023, 6:10pm UTC](https://forums.powershell.org/t/powershell-checkboxes/21275/2 "2023-01-04T18:10:29Z")

</div>

Firstly, when posting code, please format it as code:

[How to format code on PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif)

You need to add the state check to each check box:

```auto
$checkBox1 = New-Object System.Windows.Forms.CheckBox
$checkBox1.Location = New-Object System.Drawing.Point(10,50)
$checkBox1.Add_CheckStateChanged({
    if ($checkBox1.Checked -and $checkBox2.Checked -and $checkBox3.Checked) {
        $button.Enabled = $true
    }
    else {
        $button.Enabled = $false
    }
})
$form.Controls.Add($checkBox1)

$checkBox2 = New-Object System.Windows.Forms.CheckBox
$checkBox2.Location = New-Object System.Drawing.Point(150,50)
$checkBox2.Add_CheckStateChanged({
    if ($checkBox1.Checked -and $checkBox2.Checked -and $checkBox3.Checked) {
        $button.Enabled = $true
    }
    else {
        $button.Enabled = $false
    }
})
$form.Controls.Add($checkBox2)

```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/powershell-checkboxes/21275/3 "2024-05-16T20:16:06Z")

</div>


