A Revolution
From the Norm,
Towards Greatness
Home » » CSharp (C#): Intro to a ProgressBar (Basic)

CSharp (C#): Intro to a ProgressBar (Basic)

Written By Unknown on Tuesday, May 31, 2016 | 6:21 PM



Welcome back coders, today is Tuesday and it's a beautiful summer day outside to do some programming indoors. Today we are going to be learning on how to do a basic CSharp (C#) ProgressBar.


For this tutorial you are going to need,

  • Two Buttons (Start & Stop) 
  • Timer
  • ProgressBar 

Now to the fun part, the code! You can simply skip the video below, or watch it to get a step-step guide on how to do things (plus I explain things more in detail) or simply grab the code below the video. 




  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace CSharp___Ep_2_Basic_Intro_to_Progessbar
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             //Start the Timer
  21.             timer1.Start();
  22.            
  23.         }
  24.         private void button2_Click(object sender, EventArgs e)
  25.         {
  26.             //Stop the Timer
  27.             timer1.Stop();
  28.         }
  29.         private void timer1_Tick(object sender, EventArgs e)
  30.         {
  31.             //Get the progressbar moving, by 1 increment everytime Timer1 loops (# of intervals)
  32.             progressBar1.Increment(+1);
  33.             //If ProgressBar 1, is 100% done loading
  34.             if(progressBar1.Value == 100)
  35.             {
  36.                 //Then this will take place ------------------------------
  37.              
  38.                 timer1.Stop();
  39.              
  40.                 MessageBox.Show("Coder Revolt, is 100% Done");
  41.                 progressBar1.Value = 0;
  42.             }
  43.         }
  44.     }
  45. }

Thank you very much for taking the time to learn and reading this post (or plus watching the YouTube video). Hope to see you soon again, pce to the out :)
SHARE

About Unknown

0 comments :

Post a Comment