Hi all,

I am trying to make a simple application, where when a user press a button, there will be 2 consecutive images shown inside the window with delay. Below is the source code

private void btnAddMore_Click(object sender, RoutedEventArgs e)
        {
         //first show image1 in window       
            FunctImage();

         //put a "fake" delay
            for (int i = 0; i < 1000000000; i++)
            {
            }

        //draw image2 in the same position
            FunctImage2();
        }

        //function to show image1
        public void FunctImage()
        {
            System.Windows.Controls.Image img = new Image();
            img.Source = new BitmapImage(new Uri(@"C:\1.jpg"));
            img.Width = 100;
            Content = img;
        }

        //function to show image2
        public void FunctImage2()
        {

            System.Windows.Controls.Image img = new Image();
            img.Source = new BitmapImage(new Uri(@"C:\2.jpg"));
            img.Width = 100;
            Content = img;
        }

what I got when I pressed the button was only a delay and image2 was drawn.. I actually need to show image1 first and after some delay, image2 will be shown..

Thank you for the guiddance

int count=0;
private void timer1_Tick(object sender, EventArgs e)
        {
            count++;
//Picture 2 display after 30 seconds
          if(count==30)
          {
            FunctImage2();
timer1.stop;
count=0;
          }
        }
        private void InitTimer()
        {
            timer1.Enabled = true;
            timer1.Interval = 1000;
        }

private void btnAddMore_Click(object sender, RoutedEventArgs e)
{
            FunctImage();
            InitTimer();
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Hi all ! thanks a lot, I read some stuffs about timers and also tried your code. It finally works!

Edited 6 Years Ago by reza.adinata: n/a

This question has already been answered. Start a new discussion instead.