Progress Task List Control






4.58/5 (12 votes)
Sep 9, 2005
2 min read

74954

986
A simple control to display a list of tasks, being ticked off as they are completed by the program.
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:
// 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.