0
我有2個窗體,名爲Form1和Form2。以另一種形式更改按鈕的顏色C#
每個窗體都有3個按鈕同名:Button1,Button2和Button3。
我想要的是當Form1中按鈕的每種顏色都改變了,然後Form 2中按鈕的每種顏色也改變了。例如,Form 1中的Button 1是綠色的,因此Form 1中的Button 1也是綠色的。
我該怎麼做?這是我做了什麼,它不工作
Form1中
Form2 form2 = new Form2();
private void Klik_Click(object sender, EventArgs e)
{
counter++;
if(counter==1)
{
Button1.BackColor = Color.Red;
Button2.BackColor = Color.Red;
Button3.BackColor = Color.Red;
form2.Button1.BackColor = Color.Red;
form2.Button2.BackColor = Color.Red;
form2.Button3.BackColor = Color.Red;
}
if (counter > 1)
{
Button1.BackColor = Color.Green;
Button2.BackColor = Color.Green;
Button3.BackColor = Color.Green;
form2.Button1.BackColor = Color.Green;
form2.Button2.BackColor = Color.Green;
form2.Button3.BackColor = Color.Green;
counter = 0;
}
}
private void StripMenu_Click(object sender, EventArgs e)
{
form2.Show();
}
what * exactly * does not work? – ASh
@ASh - 我在Form2中按鈕的顏色沒有改變。你能幫我解決這個問題嗎? –
你如何創建所有表單? – Valentin