Click here to Skip to main content
16,021,285 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
good morning , i'm working on playing sequence of gif image ,but it always show me the last image only , i tried to write a timer that will wait 2 second before getting next image from db , but it doesn't work, could you help me please .
C#
for (int i = 0; i <= myList.Count - 1; i++)
           {
               data = myList[i].ToString();
               // Console.WriteLine(data);
               data = what_word(data);
               if (!data.Equals("not found"))
               {

                   command.CommandText = "SELECT picturename FROM pictures WHERE word = '" + data + "';";

                   command.Parameters.AddWithValue("@word", myList[i].ToString());

                   reader1 = command.ExecuteReader();


                   while (reader1.Read())
                   {

                     // Console.WriteLine(reader1[0].ToString());
                       string imagename = "D:\\grad.projec\\C#\\db1\\";
                       imagename = imagename + reader1[0].ToString();
                       //Console.WriteLine(imagename);
                     tt1 = Image.FromFile(imagename);
                   
                      pictureBox1.Image = tt1;


                   }

               }
               
               reader1.Close();

           }
Posted
Updated 21-Dec-12 0:10am
v2
Comments
OriginalGriff 21-Dec-12 5:54am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
azizamustafa 21-Dec-12 6:14am    
i edited it

1 solution

Ok, ok...this may be fun...

The problem is quite simple, but it may take a little explaining.

Lets simplify your code a bit...
C#
int myInt = 0;
for (int i = 0; i < 5; i++)
   {
   myInt = i;
   }
What would you expect that code to do? And how would it differ from:
C#
int myInt = 5 - 1;
Your code does the same thing. It reads a collection of image names from teh DB, then it converts them to Images, and assigns them one after the other to your picture box. Just like with an int, the picture box ends up with just the final value, as if your loop did not exist.

So, change your code to:
Set up a class level List of strings, and clear it before you enter your loop.
Set a class level integer to index it.
In the loop, instead of creating an image, add the name to the List.
After the loop, set the index to zero.
Now, add a Timer to your form, which has an Interval suitable for switching images.
In the Tick event handler, check the index - if it is greater than or equal to the List.Count do nothing.
Otherwise, get the List item and the index, and increment the index for next time.
Now get the Image, and set the PictureBox.Image property.
 
Share this answer
 
Comments
azizamustafa 21-Dec-12 6:53am    
for each name added to list . do i increment the index or it will stay zero?
OriginalGriff 21-Dec-12 6:55am    
No. Set it to zero after the loop - that way when the timer runs, it will start with the first one and move through them.
azizamustafa 21-Dec-12 6:56am    
ok :)
azizamustafa 21-Dec-12 7:07am    
thank you very much . its a great help from you . really thanks
OriginalGriff 21-Dec-12 8:02am    
You're welcome!

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