Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
要将不同标签的文本更改为c#_C#_Winforms - Fatal编程技术网

要将不同标签的文本更改为c#

要将不同标签的文本更改为c#,c#,winforms,C#,Winforms,我想做一个商标问答游戏。我现在做了这个代码 int a=0; private void button1_Click(object sender, EventArgs e) { pictureBox1.BackgroundImage = button1.BackgroundImage; a = 1; } private void button2_Click(object sender, EventArgs e) { pictureBox1.BackgroundImag

我想做一个商标问答游戏。我现在做了这个代码

int a=0;

private void button1_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button1.BackgroundImage;
    a = 1;

}

private void button2_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button2.BackgroundImage;
    a = 2;
}

private void button3_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button3.BackgroundImage;
    a = 3;
}

private void button4_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button4.BackgroundImage;
    a = 4;
}

private void button5_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button5.BackgroundImage;
    a = 5;
}

private void button6_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button6.BackgroundImage;
    a = 6;
}

private void button7_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button7.BackgroundImage;
    a = 7;
}

private void button8_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button8.BackgroundImage;
    a = 8;
}

private void button9_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button9.BackgroundImage;
    a = 9;
}

private void button10_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button10.BackgroundImage;
    a = 10;
}

private void button11_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button11.BackgroundImage;
    a = 11;
}

private void button12_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button12.BackgroundImage;
    a = 12;
}

private void button13_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button13.BackgroundImage;
    a = 13;
}

private void button14_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button14.BackgroundImage;
    a = 14;
}

private void button15_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button15.BackgroundImage;
    a = 15;
}

private void button16_Click(object sender, EventArgs e)
{
    pictureBox1.BackgroundImage = button16.BackgroundImage;
    a = 16;
}

private void button17_Click(object sender, EventArgs e)
{
    int i;
    int scor = 0;

    List<string> numeLogo = new List<string>(); // audi,bentley,cadillac,chevrolet,dodge,alfa romeo
    numeLogo.Add("audi");                       // ferrari,peugeot,volkswagen,trabant,mitsubishi,mazda
    numeLogo.Add("bentley");                       // opel,maserati,lamborghini,mercedes
    numeLogo.Add("cadillac");
    numeLogo.Add("chevrolet");
    numeLogo.Add("dodge");
    numeLogo.Add("alfa romeo");
    numeLogo.Add("ferrari");
    numeLogo.Add("peugeot");
    numeLogo.Add("volkswagen");
    numeLogo.Add("trabant");
    numeLogo.Add("mitsubishi");
    numeLogo.Add("mazda");
    numeLogo.Add("opel");
    numeLogo.Add("maserati");
    numeLogo.Add("lamborghini");
    numeLogo.Add("mercedes");





    for (i = 1; i <= 16; i++)
    {
        if (a == i)
            if (textBox1.Text == numeLogo[i - 1])
            {

                MessageBox.Show("bravo");


            }
            else
                MessageBox.Show("nu e bine");
    }



}
inta=0;
私有无效按钮1\u单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮1.BackgroundImage;
a=1;
}
私有无效按钮2\u单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮2.BackgroundImage;
a=2;
}
私有无效按钮3\u单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮3.BackgroundImage;
a=3;
}
私有无效按钮4_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮4.BackgroundImage;
a=4;
}
私有无效按钮5_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮5.BackgroundImage;
a=5;
}
私有无效按钮6_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮6.BackgroundImage;
a=6;
}
私有无效按钮7_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮7.BackgroundImage;
a=7;
}
私有无效按钮8_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮8.BackgroundImage;
a=8;
}
私有无效按钮9_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮9.BackgroundImage;
a=9;
}
私有无效按钮10_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮10.BackgroundImage;
a=10;
}
私有无效按钮11_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮11.BackgroundImage;
a=11;
}
私有无效按钮12_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮12.BackgroundImage;
a=12;
}
私有无效按钮13_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮13.BackgroundImage;
a=13;
}
私有无效按钮14_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮14.BackgroundImage;
a=14;
}
私有无效按钮15_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮15.BackgroundImage;
a=15;
}
私有无效按钮16_单击(对象发送者,事件参数e)
{
pictureBox1.BackgroundImage=按钮16.BackgroundImage;
a=16;
}
私有无效按钮17_单击(对象发送者,事件参数e)
{
int i;
int scor=0;
List numeLogo=new List();//奥迪、宾利、凯迪拉克、雪佛兰、道奇、阿尔法·罗密欧
numeLogo.Add(“奥迪”);//法拉利、标致、大众、特拉班特、三菱、马自达
numeLogo.Add(“宾利”);//欧宝、玛莎拉蒂、兰博基尼、梅赛德斯
numeLogo.Add(“凯迪拉克”);
numeLogo.Add(“雪佛兰”);
添加(“道奇”);
numeLogo.Add(“阿尔法罗密欧”);
numeLogo.Add(“法拉利”);
numeLogo.Add(“标致”);
numeLogo.Add(“大众”);
numeLogo.添加(“trabant”);
numeLogo.Add(“三菱”);
numeLogo.Add(“马自达”);
numeLogo.Add(“欧宝”);
numeLogo.Add(“玛莎拉蒂”);
添加(“兰博基尼”);
numeLogo.Add(“梅赛德斯”);

对于(i=1;i是的,您可以声明您的标签数组:

private List<Label> Labels { 
get { 
   return new List<Label>() {label1, label2, label3}; } 
}
私有列表标签{
获取{
返回新列表(){label1,label2,label3};}
}

与您的问题无关,但您应该将问题逻辑移动到一个或多个新类中。您可能还想看看在Winform控件中添加一些此类逻辑。