Skip to content

Instantly share code, notes, and snippets.

@drmcarvalho
Created July 25, 2016 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmcarvalho/21495978a186c00c44c7782397e88cd2 to your computer and use it in GitHub Desktop.
Save drmcarvalho/21495978a186c00c44c7782397e88cd2 to your computer and use it in GitHub Desktop.
Exemplo ProgressBar
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace ProgressBarExemplo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
Thread.Sleep(100);
backgroundWorker1.ReportProgress(i);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
Text = e.ProgressPercentage.ToString();
if (progressBar1.Value >= 1 && progressBar1.Value <= 50)
{
label1.Text = "Installing Virus";
}
else if (progressBar1.Value > 50 && progressBar1.Value <= 100)
{
label1.Text = "Downloading Virus";
}
}
private void button1_Click(object sender, EventArgs e)
{
backgroundWorker1.RunWorkerAsync();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment