Tuesday, July 27, 2010

Program to use Timer Control.


Write a program to use Timer Control.
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string[] path = new string[4];
        int count = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
            path[0] = "E:\\Blue hills.jpg";
            path[1] = "E:\\Sunset.jpg";
            path[2] = "E:\\Water lilies.jpg";
            path[3] = "E:\\Winter.jpg";
            timer1.Start();
            timer1.Interval = 1000;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            count++;
            if (count == 1)
            {
                pictureBox1.Image = Image.FromFile(path[0]);
            }
            else if (count == 2)
            {
                pictureBox1.Image = Image.FromFile(path[1]);
            }
            else if (count == 3)
            {
                pictureBox1.Image = Image.FromFile(path[2]);
            }
            else if (count == 4)
            {
                pictureBox1.Image = Image.FromFile(path[3]);
            }
            else if (count >= 5)
            {
                count = 0;
            }
        }
    }
}

No comments:

Post a Comment