C# ProgressBar and Countdown Timer - START,STOP,RESET


This is a C# progressbar and timer example.We Start,Stop and Reset our timer and progressbar.Meanwhile we update the progressbar and percentage label showing the current progress value.

Here's the code :  

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 Splasher
{
    public partial class Form1 : Form
    {

        int progress = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //INCREMENT OUR PROGRESS
            progress += 1;
            if(progress >= 100)
            {
                timer1.Enabled = false;
                timer1.Stop();
            }
            //OTHERWISE
            progressBar1.Value = progress;
            percentTxt.Text = progress.ToString()+" .00 %";
        }

        private void startBtn_Click(object sender, EventArgs e)
        {
            //ENABLE AND SET INTERVALL
            timer1.Enabled = true;
            timer1.Interval = 50;
        }

        private void stopBtn_Click(object sender, EventArgs e)
        {
            //STOP
            timer1.Stop();
            //UPDATE BUTTON TXT
            if(progress>0 && progress<100)
            {
                startBtn.Text = "Resume";
            }
        }

        private void resetBtn_Click(object sender, EventArgs e)
        {
           //RESETTING
            progress = 0;
            progressBar1.Value = 0;
            percentTxt.Text = "0.00";
        }
    }
}

Best regards.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think


Previous Post Next Post