views:

122

answers:

3

i want to change the forecolor of the checked item when it is unchecked.. for checked item i have used item.checked but what to do if it is unchecked? im using winforms

+1  A: 

item.checked is true if an item is checked, and false if an item is unchecked.

So you can do something like:

if(item.checked)
{
    //Set color
}
else
{
    //Set color of item for unchecked
}
Ikke
+2  A: 

I suppose you are looking for something like this:

private void checkBox1_CheckedChanged(object sender, EventArgs e) {
    if (checkBox1.Checked)
        checkBox1.ForeColor = Color.Green;
    else
        checkBox1.ForeColor = Color.Red;
}

As you might know, the Checked property of the CheckBox control is a boolean. So testing for checkBox1.Checked results in a changes if Checked == true, and !checkBox1.Checked (or an else block) results in changes if Checked == false

Webleeuw
+2  A: 
control.Color = checkBox.Checked ? Color.Red : Color.Blue;
thelost