问题自动更新Windows窗体中的标签 [英] Problem automatically updating labels in windows forms

查看:111
本文介绍了问题自动更新Windows窗体中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个学习阿拉伯字母的小应用程序,在这里,我希望当我点击下一个按钮时,应该显示下一个字母。为此,我自动更新标签,但是当使用if语句使用多个标签时,当我单击下一个按钮时,将显示最后一个标签数据。我的代码是这样的。

  private   void  Form1_Load( object  sender,EventArgs e)
{
pictureBox1.Image = Image.FromFile( @ D:\ thesmic projects \Aleef \Aleef \ Resources \ example_alif_1.gif);
pictureBox2.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\Allah.gif);
pictureBox3.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\Allah.gif);
pictureBox4.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\ALLAHH.jpg);
label1.Text = I;
button1.Text = II;
button2.Text = Home;

}

private void button1_Click(< span class =code-keyword> object
sender,EventArgs e)
{

if (label1。 Text == I
{
pictureBox1.Image = Image。 FromFile( @ D:\ islamic projects \ Aleef\Aleef \ Resources\circle_baa1.jpg< /跨度>);
pictureBox2.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\baab.jpeg);
pictureBox3.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\BAB.jpg);
pictureBox4.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\DOOR.jpg);
label1.Text = II;
button1.Text = III;
button2.Text = ;

}
if (label1.Text == < span class =code-string> II

{
pictureBox1.Image = Image.FromFile( @ < span class =code-string> D:\ islamic projects \ Aleef \Aleef \ Resources \ circle_taa.jpg
);
pictureBox2.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\turab.jpg);
pictureBox3.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef 。\Resources\ترابJPG);
pictureBox4.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\SOIL.jpg);
label1.Text = III;
button1.Text = IV;
button2.Text = II;
}
if (label1.Text == III
{
pictureBox1.Image = Image.FromFile( @ D:\ islamic projects \ Aleef\Aleef\Resources\circle_thaa.jpg);
pictureBox2.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\fuit.jpg);
pictureBox3.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\SAMAR.jpg);
pictureBox4.Image = Image.FromFile( @ D:\ islamic projects \Alefä\\Aleef \Resources\FRUIT.jpg);
// label1.Text = Convert.ToString(Number + 3);
// button1.Text = Convert.ToString(Number + 4);
// button2.Text = Convert.ToString(Number + 1);
label1.Text = < span class =code-string>
IV;
button1.Text = V;
button2.Text = III;
}



这时当我点击下一个按钮时,它会转到我的最后一个数据,而不是第二个。

解决方案

因为你正在使用三个if语句,如果它只运行每个if子句,那么就没有了。



在你的第一个if子句中,你将label.text设为II

之后你检查label.text是否为II,恰好是在runnig通过firt if-clause之后。



所以只需制作

如果(label1.Text ==II)

否则if(label1.Text ==II)





 if(label1 .Text ==III)

否则if(label1.Text ==III)


< blockquote>非常感谢。 @Florian Braun。


I am developing an small app learning Arabic alphabets, In this, I want when I click next button the next alphabet should display. For that, I am automatically updating Labels, but when more than one labels are used using if statement, when I click next button then the last label data is showing. My code is like this.

private void Form1_Load(object sender, EventArgs e)
       {
           pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\example_alif_1.gif");
           pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\Allah.gif");
           pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\Allah.gif");
           pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\ALLAHH.jpg");
           label1.Text = "I";
           button1.Text = "II";
           button2.Text = "Home";

       }

       private void button1_Click(object sender, EventArgs e)
       {

           if (label1.Text == "I")
           {
               pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\circle_baa1.jpg");
               pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\baab.jpeg");
               pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\BAB.jpg");
               pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\DOOR.jpg");
               label1.Text = "II";
               button1.Text = "III";
               button2.Text = "I";

           }
           if (label1.Text == "II")
           {
               pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\circle_taa.jpg");
               pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\turab.jpg");
               pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\تراب.jpg");
               pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\SOIL.jpg");
               label1.Text = "III";
               button1.Text = "IV";
               button2.Text = "II";
           }
           if (label1.Text == "III")
           {
               pictureBox1.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\circle_thaa.jpg");
               pictureBox2.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\fuit.jpg");
               pictureBox3.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\SAMAR.jpg");
               pictureBox4.Image = Image.FromFile(@"D:\islamic projects\Aleef\Aleef\Resources\FRUIT.jpg");
               //label1.Text = Convert.ToString(Number + 3);
               //button1.Text = Convert.ToString(Number + 4);
               //button2.Text = Convert.ToString(Number + 1);
               label1.Text = "IV";
               button1.Text = "V";
               button2.Text = "III";
           }


Here when I click next button then it is taking me to last data, not the second one.

解决方案

as you are using three "if statements" without else if it just runs through every if clause.

in your first if-clause you make label.text to "II"
after that you check if label.text is "II" which happens to be after runnig through firt if-clause.

so just make

if (label1.Text == "II")

to

else if (label1.Text == "II")


and

if (label1.Text == "III")

to

else if (label1.Text == "III")


Thank you very much. @Florian Braun.


这篇关于问题自动更新Windows窗体中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆