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

namespace ch15_4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            progressBar1.Minimum = 1;
            progressBar1.Maximum = 20;
            trackBar1.Minimum = 1;
            trackBar1.Maximum = 20;
        }

        private void button1_Click(object sender, EventArgs e)
        {
           const string message = "Counting the number of students : ";
           progressBar1.Step = 1;
           label1.Visible = true;
           for(int i = 0; i <= progressBar1 .Maximum ; i ++)
           {
               progressBar1.PerformStep(); // update progress bar
               label1.Text = message + i.ToString(); // set message to display
               label1.Refresh(); // needed or we won't see the label update
               System.Threading.Thread.Sleep(500);  // simulate an action that takes time
           }
           MessageBox.Show("The work is done!");
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {

        }

        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
           textBox1.Text = (trackBar1.Value).ToString();
           progressBar1.Value = trackBar1.Value;
        }
    }
}
