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 !
Firstly, when posting code, please format it as code:
How to format code on PowerShell.org
You need to add the state check to each check box:
$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)
1 Like