我有一个小问题,但首先是一些背景
如果单击正确的答案,我的按钮的背景颜色将更改为 YellowGreen,而其他三个变为红色,但我的新问题是我无法弄清楚如何做到这一点,因此如果用户单击的答案是错误的,三个错误答案变为红色,并以绿色突出显示正确答案(用户单击的按钮周围有一个明亮的边框,以通知这是所选答案)。
为了解决原来的问题,我做了以下事情:
if (btnA.Tag.ToString() == "0")
{
btnA.BackColor = Color.YellowGreen;
btnB.BackColor = Color.Red;
btnC.BackColor = Color.Red;
btnD.BackColor = Color.Red;
}
我对数字 0-4 做了上述四次(数组中的四个可能答案;表格上的 A、B、C 或 D。
我的代码现在如下:
private void button4_Click(object sender, EventArgs e)
{
//Disables the buttons upon clicking
btnA.Font = new Font(btnA.Font.Name, btnA.Font.Size, FontStyle.Bold);
btnA.FlatAppearance.BorderColor = Color.Cyan;
btnA.FlatAppearance.BorderSize = 3;
btnA.Enabled = false;
btnB.Enabled = false;
btnC.Enabled = false;
btnD.Enabled = false;
if (btnA.Tag.ToString() == "0")
{
btnA.BackColor = Color.YellowGreen;
btnB.BackColor = Color.Red;
btnC.BackColor = Color.Red;
btnD.BackColor = Color.Red;
}
if (btnA.Tag.ToString() == "0")
{
iCorrect++;
if (debugMode)
{
Debug.WriteLine("Correct: " + iCorrect.ToString());
}
}
}
private void button5_Click(object sender, EventArgs e)
{
//
btnB.Font = new Font(btnB.Font.Name, btnB.Font.Size, FontStyle.Bold);
btnB.FlatAppearance.BorderColor = Color.Cyan;
btnB.FlatAppearance.BorderSize = 3;
btnA.Enabled = false;
btnB.Enabled = false;
btnC.Enabled = false;
btnD.Enabled = false;
if (btnA.Tag.ToString() == "1")
{
btnA.BackColor = Color.Red;
btnB.BackColor = Color.YellowGreen;
btnC.BackColor = Color.Red;
btnD.BackColor = Color.Red;
}
if (btnA.Tag.ToString() == "1")
{
iCorrect++;
if (debugMode)
{
Debug.WriteLine("Correct: " + iCorrect.ToString());
}
}
}
private void button6_Click(object sender, EventArgs e)
{
//
btnC.Font = new Font(btnC.Font.Name, btnC.Font.Size, FontStyle.Bold);
btnC.FlatAppearance.BorderColor = Color.Cyan;
btnC.FlatAppearance.BorderSize = 3;
btnA.Enabled = false;
btnB.Enabled = false;
btnC.Enabled = false;
btnD.Enabled = false;
if (btnA.Tag.ToString() == "2")
{
btnA.BackColor = Color.Red;
btnB.BackColor = Color.Red;
btnC.BackColor = Color.YellowGreen;
btnD.BackColor = Color.Red;
}
if (btnA.Tag.ToString() == "2")
{
iCorrect++;
if (debugMode)
{
Debug.WriteLine("Correct: " + iCorrect.ToString());
}
}
}
private void button7_Click(object sender, EventArgs e)
{
//
btnD.Font = new Font(btnD.Font.Name, btnD.Font.Size, FontStyle.Bold);
btnD.FlatAppearance.BorderColor = Color.Cyan;
btnD.FlatAppearance.BorderSize = 3;
btnA.Enabled = false;
btnB.Enabled = false;
btnC.Enabled = false;
btnD.Enabled = false;
if (btnA.Tag.ToString() == "3")
{
btnA.BackColor = Color.Red;
btnB.BackColor = Color.Red;
btnC.BackColor = Color.Red;
btnD.BackColor = Color.YellowGreen;
}
if (btnA.Tag.ToString() == "3")
{
iCorrect++;
if (debugMode)
{
Debug.WriteLine("Correct: " + iCorrect.ToString());
}
}
}
}
}
我尝试了一些不同的事情,但它不断导致奇怪的事情,这些事情基本上不是我想做的,我无法弄清楚我需要使用什么样的语法或代码来完成这个。