Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
C#
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.
Posted

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")
 
Share this answer
 
v2
Thank you very much. @Florian Braun.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900