[英]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?我想在未选中时更改已选中项目的前景色.. 对于已选中的项目,我使用了 item.checked 但如果未选中该怎么办? im using winforms
我正在使用 winforms
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.您可能知道,CheckBox 控件的 Checked 属性是一个布尔值。 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因此,如果 Checked == true 则测试
checkBox1.Checked
导致更改,如果 Checked == false 则!checkBox1.Checked
(或 else 块)会导致更改
control.Color = checkBox.Checked ? Color.Red : Color.Blue;
item.checked is true if an item is checked, and false if an item is unchecked. item.checked 如果一个项目被选中,则为 true,如果一个项目未被选中,则为 false。
So you can do something like:因此,您可以执行以下操作:
if(item.checked)
{
//Set color
}
else
{
//Set color of item for unchecked
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.