Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the color of the item when the checkbox is unchecked in c#.net?

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

like image 458
zoya Avatar asked Jan 23 '23 10:01

zoya


2 Answers

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

like image 184
Webleeuw Avatar answered Jan 25 '23 23:01

Webleeuw


control.Color = checkBox.Checked ? Color.Red : Color.Blue;
like image 29
thelost Avatar answered Jan 26 '23 00:01

thelost