Click here to Skip to main content
15,885,985 members
Articles / Programming Languages / C#
Article

Progress Task List Control

Rate me:
Please Sign up or sign in to vote.
4.58/5 (13 votes)
12 Sep 20052 min read 73.6K   981   73   16
A simple control to display a list of tasks, being ticked off as they are completed by the program.

Sample Image

Introduction

With some tasks, you just need a progress bar to tell the user how fast a task is going. You may have used a label or status bar with a progress bar, to tell the user what task is currently being performed. This control shows all the tasks that need to be performed, and ticks them off one by one as they are completed.

Using the code

It's very easy to use this control. Just add a reference in your Windows Forms project to ProgressTaskList.dll (contained in the source and demo projects). If it doesn't appear in the VS toolbox, you can right-click and 'Add/Remove Items', browse to the DLL and click OK. Then simply drag it on to your form surface.

You can set the tasks through the Visual Studio designer. See the 'TaskItems' property, and click the (Collection) button to edit the items. Put one task on each line.

Alternatively, you can set the tasks programmatically:

C#
// To add items programatically, use the following syntax:
this.progressTaskList1.TaskItems.AddRange(new string[]{"Loading", 
       "Initialising", "Whatever", "Saving"});

// or you can just use the normal Add() method
this.progressTaskList1.TaskItems.Add("Loading");
this.progressTaskList1.TaskItems.Add("Initialising");
...

You need to call Start() to draw the tasks in the control, and after that call NextTask() whenever a task is completed, to advance to the next task.

Points of Interest

I was amazed to find that the Panel control has a built-in function called ScrollControlIntoView which ensures that the specified control is visible. I was about to go and write my own one, but lo and behold it was there. I used this method to ensure that the current task is always visible. As can be seen in the screenshot to the right, if there are too many tasks to fit in the panel surface, the control handles scrolling gracefully, thanks to the AutoScroll property of the Panel.

How it works

The control has a property called TaskItems which is a string[], corresponding to the tasks needing to be performed. I should point out that there is no link between the control and the thread running the task. So in order to update the control to the next task, the program must call NextTask() on the control after each task is complete.

When the Start() method is invoked on the control, the labels are created dynamically and added to the panel. Each label has an image on its left hand side, which changes from an arrow to a tick when the task is finished.

It's quite simple really. The hardest part (by far) was getting the TaskItems collection property to work through the VS designer. It was a useful exercise in control design.

Conclusions

Feel free to use this control and modify it as you please. If you have the time, post any improvements you make to the control here (as a comment), and I'll update the article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionSource Code VB Pin
rgaspar3-Apr-09 3:54
rgaspar3-Apr-09 3:54 
AnswerRe: Source Code VB Pin
Tim_Mackey3-Apr-09 6:17
Tim_Mackey3-Apr-09 6:17 
GeneralRe: Source Code VB Pin
rgaspar3-Apr-09 10:33
rgaspar3-Apr-09 10:33 
GeneralCommercial Usage Pin
Eric SE26-Jul-07 16:11
Eric SE26-Jul-07 16:11 
GeneralRe: Commercial Usage Pin
Tim_Mackey26-Jul-07 21:50
Tim_Mackey26-Jul-07 21:50 
GeneralMessage Closed Pin
27-Dec-10 8:43
outpan27-Dec-10 8:43 
QuestionImages Pin
salsafyren228-Mar-06 0:19
salsafyren228-Mar-06 0:19 
AnswerRe: Images Pin
Tim_Mackey28-Mar-06 0:23
Tim_Mackey28-Mar-06 0:23 
QuestionAbout BeginInvoke()? Pin
firerainbow7-Oct-05 3:56
firerainbow7-Oct-05 3:56 
AnswerRe: About BeginInvoke()? Pin
Tim_Mackey7-Oct-05 5:40
Tim_Mackey7-Oct-05 5:40 
GeneralRe: About BeginInvoke()? Pin
firerainbow8-Oct-05 5:06
firerainbow8-Oct-05 5:06 
GeneralSource & Demo File Names Pin
fwsouthern15-Sep-05 18:00
fwsouthern15-Sep-05 18:00 
AnswerRe: Source & Demo File Names Pin
Tim_Mackey15-Sep-05 23:16
Tim_Mackey15-Sep-05 23:16 
GeneralRe: Source & Demo File Names Pin
fwsouthern16-Sep-05 16:47
fwsouthern16-Sep-05 16:47 
GeneralVery cool Pin
Tomasz Bekasiewicz12-Sep-05 11:43
Tomasz Bekasiewicz12-Sep-05 11:43 
AnswerRe: Very cool Pin
Tim_Mackey12-Sep-05 11:59
Tim_Mackey12-Sep-05 11:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.