SlideShare a Scribd company logo
1 of 11
Submitted by: MUHAMMAD USMAN
SALEEM (543)
Submitted to: ZAHID ASLAM & WHOLE CLASS
Progress-Bar
INTRODUCTION
Progress-Bar indicates visually the progress of
an operation. It is best used on a long-running
computation or task. And the Background-Worker
is often used to perform that task—it does not
block the interface.
Continue...
Example: Please add a Progress-Bar control to
your Windows-Forms program by double-clicking
on the Progress Bar entry in the Toolbox. For this
example, we also need a Background Worker—
add one and then create the event handlers
required.
Note : We need the Load event handler, the Do
Work event handler, and the Progress Changed
event handler.
Example that uses Progress Bar
and Background Worker: C#
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Continue...
private void Form1_Load(object sender, System.EventArgs e)
{
// Start the BackgroundWorker.
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender,
DoWorkEventArgs e)
{
for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(100);
// Report progress. backgroundWorker1.
ReportProgress(i);
}
Continue…
private void backgroundWorker1_ProgressChanged(object
sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the
BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text.
this.Text = e.ProgressPercentage.ToString();
}
}
}
Starting the background task
In the Form1_Load event handler, please add a
method call to the Run-Worker-Async method on
the Background-Worker instance. This will create
a thread and the Do-Work method will begin.
METHOD
Inside the Do-Work event handler, we loop
over the numbers 1 through 100. At each
iteration, we wait one-tenth of a second. Then, we
call the Report-Progress method on the
Background-Worker instance.
And:
In Progress-Changed, we set the value of the
Progress-Bar to the Progress-Percentage
property of the Progress-Changed-EventArgs
argument.
PROPERTY
Color
One of the useful properties on the Progress-Bar
is the Fore-Color property. This can be set to a
Color value to change the color of the bar itself
that is drawn on the screen. It is often better to
use the default color.
Note:In this screenshot, we see a yellow bar
instead of the default blue bar. This is likely a bad
design decision.
Summary
The Progress-Bar control is often used in
conjunction with a threading mechanism such as
Background-Worker. With its many options, the
Progress-Bar makes a suitable widget for letting
your users know the application is still active.
THANKS

More Related Content

What's hot

Alice3 Introduction
Alice3 IntroductionAlice3 Introduction
Alice3 Introductionelketeaches
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programminghikrittiwit
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingGamee Nopnop
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingiceana
 
Introduction to programming what is programming it deal with the study of com...
Introduction to programming what is programming it deal with the study of com...Introduction to programming what is programming it deal with the study of com...
Introduction to programming what is programming it deal with the study of com...Thampaphon Thianwongsagon
 
Introduction to-programming (1)
Introduction to-programming (1)Introduction to-programming (1)
Introduction to-programming (1)Nattaporn Bunmak
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programmingPTtp WgWt
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programmingpakhpoom00110
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programmingNattaporn Bunmak
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingfahsai imjai
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programmingkhwan_thananda
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programmingPOom'z RCz
 
Introduction to programming
Introduction  to programmingIntroduction  to programming
Introduction to programmingGamee Nopnop
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programmingGamee Nopnop
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingsennysns
 

What's hot (18)

Alice3 Introduction
Alice3 IntroductionAlice3 Introduction
Alice3 Introduction
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to programming what is programming it deal with the study of com...
Introduction to programming what is programming it deal with the study of com...Introduction to programming what is programming it deal with the study of com...
Introduction to programming what is programming it deal with the study of com...
 
Introduction to-programming (1)
Introduction to-programming (1)Introduction to-programming (1)
Introduction to-programming (1)
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to programming
Introduction  to programming	Introduction  to programming
Introduction to programming
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to programming
Introduction  to programmingIntroduction  to programming
Introduction to programming
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 

Similar to Progress bar

Flow based programming in golang
Flow based programming in golangFlow based programming in golang
Flow based programming in golangAnton Stepanenko
 
]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3Klaus Hofeditz
 
Abap objects in action
Abap objects in actionAbap objects in action
Abap objects in actionFaina Fridman
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c languagekamalbeydoun
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slidesDavid Barreto
 
Step by step lsmw tutorial
Step by step lsmw tutorialStep by step lsmw tutorial
Step by step lsmw tutorialraonivaz
 
How To Use IO Monads in Scala?
 How To Use IO Monads in Scala? How To Use IO Monads in Scala?
How To Use IO Monads in Scala?Knoldus Inc.
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeansHuu Bang Le Phan
 
Getting started with code composer studio v3.3 for tms320 f2812
Getting started with code composer studio v3.3 for tms320 f2812Getting started with code composer studio v3.3 for tms320 f2812
Getting started with code composer studio v3.3 for tms320 f2812Pantech ProLabs India Pvt Ltd
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonfNataliya Patsovska
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automationMario Fusco
 
Event handling63
Event handling63Event handling63
Event handling63myrajendra
 
Uber's Journey in Distributed Deep Learning
Uber's Journey in Distributed Deep LearningUber's Journey in Distributed Deep Learning
Uber's Journey in Distributed Deep Learninginside-BigData.com
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfROWELL MARQUINA
 

Similar to Progress bar (20)

Flow based programming in golang
Flow based programming in golangFlow based programming in golang
Flow based programming in golang
 
]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3]project-open[ Workflow Developer Tutorial Part 3
]project-open[ Workflow Developer Tutorial Part 3
 
Abap objects in action
Abap objects in actionAbap objects in action
Abap objects in action
 
Lect 3-4 Zaheer Abbas
Lect 3-4 Zaheer AbbasLect 3-4 Zaheer Abbas
Lect 3-4 Zaheer Abbas
 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
IBM Business Automation Workflow
IBM Business Automation WorkflowIBM Business Automation Workflow
IBM Business Automation Workflow
 
Step by step lsmw tutorial
Step by step lsmw tutorialStep by step lsmw tutorial
Step by step lsmw tutorial
 
How To Use IO Monads in Scala?
 How To Use IO Monads in Scala? How To Use IO Monads in Scala?
How To Use IO Monads in Scala?
 
Java script
Java scriptJava script
Java script
 
03b loops
03b   loops03b   loops
03b loops
 
Book management system
Book management systemBook management system
Book management system
 
Debugger & Profiler in NetBeans
Debugger & Profiler in NetBeansDebugger & Profiler in NetBeans
Debugger & Profiler in NetBeans
 
Getting started with code composer studio v3.3 for tms320 f2812
Getting started with code composer studio v3.3 for tms320 f2812Getting started with code composer studio v3.3 for tms320 f2812
Getting started with code composer studio v3.3 for tms320 f2812
 
Declarative presentations UIKonf
Declarative presentations UIKonfDeclarative presentations UIKonf
Declarative presentations UIKonf
 
Kogito: cloud native business automation
Kogito: cloud native business automationKogito: cloud native business automation
Kogito: cloud native business automation
 
Roamer World
Roamer WorldRoamer World
Roamer World
 
Event handling63
Event handling63Event handling63
Event handling63
 
Uber's Journey in Distributed Deep Learning
Uber's Journey in Distributed Deep LearningUber's Journey in Distributed Deep Learning
Uber's Journey in Distributed Deep Learning
 
Lesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdfLesson 1 - Algorithm and Flowcharting.pdf
Lesson 1 - Algorithm and Flowcharting.pdf
 

Recently uploaded

24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 

Recently uploaded (20)

24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 

Progress bar

  • 1. Submitted by: MUHAMMAD USMAN SALEEM (543) Submitted to: ZAHID ASLAM & WHOLE CLASS Progress-Bar
  • 2. INTRODUCTION Progress-Bar indicates visually the progress of an operation. It is best used on a long-running computation or task. And the Background-Worker is often used to perform that task—it does not block the interface.
  • 3. Continue... Example: Please add a Progress-Bar control to your Windows-Forms program by double-clicking on the Progress Bar entry in the Toolbox. For this example, we also need a Background Worker— add one and then create the event handlers required. Note : We need the Load event handler, the Do Work event handler, and the Progress Changed event handler.
  • 4. Example that uses Progress Bar and Background Worker: C# using System.ComponentModel; using System.Threading; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); }
  • 5. Continue... private void Form1_Load(object sender, System.EventArgs e) { // Start the BackgroundWorker. backgroundWorker1.RunWorkerAsync(); } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { for (int i = 1; i <= 100; i++) { // Wait 100 milliseconds. Thread.Sleep(100); // Report progress. backgroundWorker1. ReportProgress(i); }
  • 6. Continue… private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e) { // Change the value of the ProgressBar to the BackgroundWorker progress. progressBar1.Value = e.ProgressPercentage; // Set the text. this.Text = e.ProgressPercentage.ToString(); } } }
  • 7. Starting the background task In the Form1_Load event handler, please add a method call to the Run-Worker-Async method on the Background-Worker instance. This will create a thread and the Do-Work method will begin.
  • 8. METHOD Inside the Do-Work event handler, we loop over the numbers 1 through 100. At each iteration, we wait one-tenth of a second. Then, we call the Report-Progress method on the Background-Worker instance. And: In Progress-Changed, we set the value of the Progress-Bar to the Progress-Percentage property of the Progress-Changed-EventArgs argument.
  • 9. PROPERTY Color One of the useful properties on the Progress-Bar is the Fore-Color property. This can be set to a Color value to change the color of the bar itself that is drawn on the screen. It is often better to use the default color. Note:In this screenshot, we see a yellow bar instead of the default blue bar. This is likely a bad design decision.
  • 10. Summary The Progress-Bar control is often used in conjunction with a threading mechanism such as Background-Worker. With its many options, the Progress-Bar makes a suitable widget for letting your users know the application is still active.