3

i try'd use Visible and Enabled under "if CheckBox3.Checked", but it's not work =( How make this works?

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
    
$Form = New-Object System.Windows.Forms.Form
$Form.AutoSize = $true
    
$CheckBox1 = New-Object System.Windows.Forms.CheckBox
$CheckBox1.Text = '1'
$CheckBox1.AutoSize = $true
$CheckBox1.Checked = $true
$CheckBox1.Location  = New-Object System.Drawing.Point(10,10)
$Form.Controls.Add($CheckBox1)
    
$CheckBox2 = New-Object System.Windows.Forms.CheckBox
$CheckBox2.Text = '2'
$CheckBox2.AutoSize = $true
$CheckBox2.Checked = $true
$CheckBox2.Location  = New-Object System.Drawing.Point(10,40)
$Form.Controls.Add($CheckBox2)
    
$CheckBox3 = New-Object System.Windows.Forms.CheckBox
$CheckBox3.Text = '3'
$CheckBox3.AutoSize = $true
$CheckBox3.Checked = $false
$CheckBox3.Location  = New-Object System.Drawing.Point(10,70)
$Form.Controls.Add($CheckBox3)
    
$FormComboBox = New-Object System.Windows.Forms.ComboBox
$FormComboBox.Enabled = $false
# OR
# $FormComboBox.Visible = $false

$FormComboBox.Text = "choise:"
$FormComboBox.Width = 120
$FormComboBox.Location = New-Object System.Drawing.Point(70,70)
$FormComboBox.Items.Add("item1");
$FormComboBox.Items.Add("item2");
$FormComboBox.Items.Add("item3");
$FormComboBox.selectedIndex = -1 
$Form.Controls.Add($FormComboBox)

if ($CheckBox3.Checked){ $FormComboBox.Enabled = $true  }
# OR
# if ($CheckBox3.Checked){ $FormComboBox.Visible = $true  }

$FormButton = New-Object System.Windows.Forms.Button
$FormButton.Location = New-Object System.Drawing.Point(100,235)
$FormButton.Size = New-Object System.Drawing.Size(120,30)
$FormButton.Text = "Start"
$Form.Controls.Add($FormButton)
    
$FormButton.Add_Click({
        if($checkBox1.Checked){ Write-Host "flag 1" }
        if($checkBox2.Checked){ Write-Host "flag 2" }
        if($checkBox3.Checked){ Write-Host "flag 3" }
        })
    
$Form.ShowDialog() | Out-Null
$Form.Dispose()
0

1 Answer 1

3

I found the solution myself:

$CheckBox3.Add_CheckStateChanged({
if ($CheckBox3.Checked){ $FormComboBox.Enabled = $true }
else { $FormComboBox.Enabled = $falce }
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.