PictureBox With Timer Control in -- Windows Forms Application c#

PictureBox Control:
The Windows Forms PictureBox control is used to display graphics in bitmap, GIF, JPEG, metafile, or icon format.

 How to: Set Pictures at Run Time (Windows Forms)




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace pictureboxtimercomboboxprogressbar
{
    public partial class Form1 : Form
    {
        string[] images = { "1.jpg", "2.jpg", "3.jpg" };
        int index = 0;
        public Form1()
        {
            InitializeComponent();
        }

       

        private void timer1_Tick(object sender, EventArgs e)
        {
            textBox1.Text = DateTime.Now.ToLongTimeString();
            pictureBox1.Image = Image.FromFile(@"C:\Users\student\OneDrive\Pictures\Camera Roll\" + images[index]);
            if (index >= images.Length-1)
                index = 0;
            else
                index++;

        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (comboBox1.SelectedItem.ToString())
            {
                case "Normal":
                    pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
                    break;
                case "StretchImage":
                       pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    break;
                case "AutoSize":
                       pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
                    break;
                case "CenterImage":
                       pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
                    break;
                case "Zoom":
                       pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
                    break;
            }
          
           
        }

             
    }
}

Comments