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

use the timer function.

this is an example of usage for timer function
http://www.csharphelp.com/2006/02/c-timer-demo/

I guess you could play with enabled property when clicked do enabled and in the ticker on interval disable and do what you need this way the delay is only invoked when you want it.

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();
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.