Click here to Skip to main content
13,199,680 members (63,373 online)
Click here to Skip to main content
Add your own
alternative version


103 bookmarked
Posted 15 Jul 2006

A progress disk similar to that in SQL Server 2005

, 31 May 2007
Rate this:
Please Sign up or sign in to vote.
The use of built-in methods of GDI+ to draw a progress disk similar to the one in SQL Server 2005

Sample screenshot


Progress disk is a simple control that I wrote after I saw the one in SQL Server 2005. It can be used to replace the old progress bar with a nice and colorful mix of gradient colors.


The .NET 2.0 class library has the Graphics object, which is responsible for drawing 2D shapes. It has primitive shapes such as point, line, rectangle, ellipse, pie, etc. I used the DrawPie method to draw my control, which is formed by drawing 3 pie layers over top of each other:

  • The first layer in the bottom: a pie having a start angle of zero and a sweep angle of 360 degrees to draw a full circle that serves as the background of the control
  • The second layer in the middle: a pie that represent the blocks of the disk; 12 blocks (pie pieces) have been drawn, each having a sweep angle of 25 degrees and a separating angle of 5
  • The third layer in the top: similar to the first layer, but its function is to control the size of the blocks; the smaller the circle drawn, the bigger the blocks appear (i.e. having an inner circle with radius zero would give blocks having the shape of slices of a pizza)


I used a linear gradient brush to fill in the blocks: 2 colors for the inactive blocks and 2 for the active block. Properties added to keep the control flexible include:

  • Value: The current value of the progress disk
  • BackGroundColor: The color of the background
  • ActiveForeColor1 & ActiveForeColor2: These 2 for the block of current value
  • InactiveForeColor1 & ActiveForeColor2: These 2 for the rest of the blocks
  • SquareSize: The side length of the square containing the control
  • BlockSize: An enum for 6 different sizes
  • SliceNumber: The number of slices in the control (added by Coyotelapa)


4 GraphicsPath objects were used to draw the control, one for each layer and an extra one to color the block with the current value.

protected override void OnPaint(PaintEventArgs e)
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        region = new Region(ClientRectangle);
        if (backGrndColor == Color.Transparent)
            Region = region;

        e.Graphics.FillPath(new SolidBrush(backGrndColor), bkGroundPath1);
        new LinearGradientBrush(new Rectangle(0, 0, size, size),
            inactiveforeColor1, inactiveforeColor2,
        value * 360 / 12, true), valuePath);
        new LinearGradientBrush(new Rectangle(0, 0, size, size),
            activeforeColor1, activeforeColor2,
        value * 360 / 12, true), freGroundPath);
        e.Graphics.FillPath(new SolidBrush(backGrndColor), bkGroundPath2);


//The Render method called on any change to control(size,colors,..)
private void Render()

        bkGroundPath1.AddPie(new Rectangle(0, 0, size, size), 0, 360);

        //just in case...
        if (sliceCount == 0)
            sliceCount = 12;

        float sliceAngle = 360 / sliceCount;
        float sweepAngle = sliceAngle - 5;
        for (int i = 0; i < sliceCount; i++)
            if (value != i)
                valuePath.AddPie(0, 0, size, size, i * sliceAngle,
        (size / 2 - size * blockRatio), (size / 2 - size * blockRatio),
        (blockRatio * 2 * size), (blockRatio * 2 * size), 0, 360);
        freGroundPath.AddPie(new Rectangle(0, 0, size, size),
            value * sliceAngle, sweepAngle);


  • 16 July, 2006 - Original version posted
  • 29 July, 2006 - Updated after adding improvements made by Coyotelapa and fixing some bugs
  • 31 May, 2007 - Article edited and moved to the main article base


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Amr Elsehemy ®
Software Developer (Senior)
Egypt Egypt

Amr is an iOS developer living in Cairo/Egypt.

Works now as Lead Software Engineer at ITWorx.

Main interests : iPhone/iPad/Mac app development.

Others :
Windows,GDI+,SqlServer, ASP.Net,Custom controls and others.

BSc Computer and Information Sciences June 2006.

MCTS:SQL Server 2005

Blog: here

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Saumitra Kumar Paul9-Jul-11 22:39
memberSaumitra Kumar Paul9-Jul-11 22:39 
SuggestionUpdate Pin
Jayke Huempfner29-Jun-11 21:37
memberJayke Huempfner29-Jun-11 21:37 
AnswerProgressDisk whit IsIndeterminate Pin
Carlos Gutierrez29-Jan-09 5:07
memberCarlos Gutierrez29-Jan-09 5:07 
QuestionSlight clipping? Pin
mentatmatt25-Jun-08 4:07
membermentatmatt25-Jun-08 4:07 
GeneralVery Nice Pin
Paul Conrad1-Jun-07 15:50
memberPaul Conrad1-Jun-07 15:50 
GeneralRe: Very Nice Pin
Amr Elsehemy®3-Jun-07 10:33
memberAmr Elsehemy®3-Jun-07 10:33 
GeneralRe: Very Nice Pin
Paul Conrad3-Jun-07 15:06
memberPaul Conrad3-Jun-07 15:06 
GeneralRe: Very Nice Pin
Amr Elsehemy®1-Aug-07 0:57
memberAmr Elsehemy®1-Aug-07 0:57 
GeneralCopyright Problem Pin
Pixelated1-Aug-06 19:15
memberPixelated1-Aug-06 19:15 
GeneralRe: Copyright Problem Pin
Amr Aly Elsehemy2-Aug-06 7:04
memberAmr Aly Elsehemy2-Aug-06 7:04 
GeneralThis rocks! Pin
Pixelated1-Aug-06 18:58
memberPixelated1-Aug-06 18:58 
GeneralRe: This rocks! Pin
Amr Aly Elsehemy2-Aug-06 7:09
memberAmr Aly Elsehemy2-Aug-06 7:09 
GeneralRe: This rocks! Pin
Pixelated2-Aug-06 10:32
memberPixelated2-Aug-06 10:32 
GeneralBuilt-in timer Pin
MerryWanderer28-Jul-06 13:50
memberMerryWanderer28-Jul-06 13:50 
GeneralSliceCount Pin
tim_mcgwyn27-Jul-06 23:39
membertim_mcgwyn27-Jul-06 23:39 
GeneralRe: SliceCount Pin
Coyotelapa14-Aug-06 0:56
memberCoyotelapa14-Aug-06 0:56 
GeneralBug Fixes / Improvements Pin
Coyotelapa17-Jul-06 4:21
memberCoyotelapa17-Jul-06 4:21 
GeneralRe: Bug Fixes / Improvements Pin
Amr Aly Elsehemy18-Jul-06 13:56
memberAmr Aly Elsehemy18-Jul-06 13:56 
GeneralRe: Bug Fixes / Improvements Pin
Coyotelapa18-Jul-06 22:01
memberCoyotelapa18-Jul-06 22:01 
GeneralResize problem Pin
tzvi16-Jul-06 8:38
membertzvi16-Jul-06 8:38 
GeneralRe: Resize problem Pin
Amr Aly Elsehemy16-Jul-06 13:10
memberAmr Aly Elsehemy16-Jul-06 13:10 
GeneralTip Pin
leppie16-Jul-06 7:00
memberleppie16-Jul-06 7:00 
GeneralRe: Tip Pin
Amr Aly Elsehemy16-Jul-06 7:10
memberAmr Aly Elsehemy16-Jul-06 7:10 
GeneralA bug... Pin
Vlad Stanciu16-Jul-06 6:35
memberVlad Stanciu16-Jul-06 6:35 
GeneralRe: A bug... Pin
Amr Aly Elsehemy16-Jul-06 6:49
memberAmr Aly Elsehemy16-Jul-06 6:49 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171020.1 | Last Updated 31 May 2007
Article Copyright 2006 by Amr Elsehemy ®
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid