我有一个带有 10 个按钮的表单。
当我点击任何一个按钮时,它应该被禁用,这样我就不能再次点击它,但是当我点击任何其他按钮时,它应该被重新启用。
我知道有一种方法可以禁用和启用控件(按钮),但我不想使用此方法,因为我想在使用时(单击时)更改按钮的颜色,并且如果按钮被禁用,它将获得其原始颜色。
所以我想知道是否有办法做到这一点。谢谢
最后我找到了一种方法。
bool[] buttons = new bool[10];
private void button1_Click(object sender, EventArgs e)
{
if (buttons[0])
{
// Code.....
buttonToggle(0);
// Here I change the color based on the estate of the correspondent bool variable
}
}
private void buttonToggle(int btn)
{
buttons[btn] = false;
for(int i = 0; i<10; i++)
{
if (i != btn)
{
buttons[i] = true;
}
}
}
感谢@TheGeneral 的想法
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句