Click here to Skip to main content
15,886,689 members
Articles / Multimedia / GDI+
Article

SQL Server 2005 Circular Progress Bar

Rate me:
Please Sign up or sign in to vote.
4.86/5 (68 votes)
26 Sep 2006CPOL1 min read 266.6K   10.4K   201   77
Shows a spinning progress bar, identical to the SQL Server 2005 busy indicator, without requiring any code.

Sample Image - sql2005circularprogress.jpg

Introduction

After initially searching for the animation used in SQL Server 2005 as an AVI or GIF, I stumbled across the excellent article by Amr Aly Elsehemy, here at The Code Project. Although good code, and indeed a starting point for what I have created, it didn't actually replicate the look and feel of the Microsoft SQL Server 2005 'busy' animation.

At less than 220 lines, I think that this control is pretty compact, and it seems to perform well, even when other threads in my application are busy.

Code

I store each 'segment' of the progress bar in an array, this makes it easy to iterate through later.

VB
Private segmentPaths(11) As Drawing2D.GraphicsPath

The segments are initialized in the CalculateSegments method, which is called when the control is initialized or resized. This method also generates a region which is used to clip the center circle back out when painting the control.

VB
'Create 12 segment pieces
For intCount As Integer = 0 To 11
    secmentPaths(intCount) = New Drawing2D.GraphicsPath

    'We subtract 90 so that the starting segment is at 12 o'clock
    secmentPaths(intCount).AddPie(rctFull, (intCount * 30) - 90, 25)
Next

The ProgressDisk_Paint method is where all the real work goes on (with the exception of the automatic iteration). I think the code speaks for itself, especially the comments :-)

VB
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
e.Graphics.ExcludeClip(innerBackgroundRegion)

For intCount As Integer = 0 To 11
    If Me.Enabled Then
        If intCount = m_TransitionSegment Then
            'If this segment is the transistion segment, colour it differently
            e.Graphics.FillPath(New SolidBrush(m_TransistionColour), _
                                segmentPaths(intCount))
        ElseIf intCount < m_TransitionSegment Then
            'This segment is behind the transistion segment
            If m_BehindIsActive Then
                'If behind the transistion should be active, 
                'colour it with the active colour
                e.Graphics.FillPath(New SolidBrush(m_ActiveColour),_
                                    segmentPaths(intCount))
            Else
                'If behind the transistion should be in-active, 
                'colour it with the in-active colour
                e.Graphics.FillPath(New SolidBrush(m_InactiveColour), _
                                    segmentPaths(intCount))
            End If
        Else
            'This segment is ahead of the transistion segment
            If m_BehindIsActive Then
                'If behind the the transistion should be active, 
                'colour it with the in-active colour
                e.Graphics.FillPath(New SolidBrush(m_InactiveColour),_
                                    segmentPaths(intCount))
            Else
                'If behind the the transistion should be in-active, 
                'colour it with the active colour
                e.Graphics.FillPath(New SolidBrush(m_ActiveColour),_
                                    segmentPaths(intCount))
            End If
        End If
    Else
        'Draw all segments in in-active colour if not enabled
        e.Graphics.FillPath(New SolidBrush(m_InactiveColour), _
                            segmentPaths(intCount))
    End If
Next
The only other real work is done by the timer increment, which is fired by default every 100ms, but this is exposed as a property.
VB
If m_TransitionSegment = 11 Then
    m_TransitionSegment = 0
    m_BehindIsActive = Not m_BehindIsActive
ElseIf m_TransitionSegment = -1 Then
    m_TransitionSegment = 0
Else
    m_TransitionSegment += 1
End If

Invalidate()

The m_BehindIsActive variable decided whether all the segments behind (anti-clockwise) the transision segment (the segment currently changing colour) should be coloured using the active or inactive colour, both of which are user definable.

License

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


Written By
Architect eNate Ltd
United Kingdom United Kingdom
Technical Architect for an expanding software company in the UK. Andrew has spearheaded the development for an internationally used, enterprise-class business process management system built in .Net.

Comments and Discussions

 
GeneralRe: What's wrong? Pin
dherrmann30-Aug-07 3:09
dherrmann30-Aug-07 3:09 
AnswerRe: What's wrong? Pin
ateece30-Aug-07 3:18
ateece30-Aug-07 3:18 
GeneralRe: What's wrong? Pin
dherrmann30-Aug-07 4:45
dherrmann30-Aug-07 4:45 
GeneralRe: What's wrong? Pin
ateece30-Aug-07 5:45
ateece30-Aug-07 5:45 
GeneralI dont know how to use it Pin
Leonel F.4-Jul-07 22:13
Leonel F.4-Jul-07 22:13 
AnswerRe: I dont know how to use it PinPopular
ateece5-Jul-07 2:57
ateece5-Jul-07 2:57 
GeneralRe: I dont know how to use it Pin
Leonel F.6-Jul-07 7:40
Leonel F.6-Jul-07 7:40 
GeneralCOOL Pin
Hypothalamus5-Jun-07 3:49
Hypothalamus5-Jun-07 3:49 
A+

Hi

QuestionMS ACCESS Pin
Floodguy6-Mar-07 19:23
Floodguy6-Mar-07 19:23 
AnswerRe: MS ACCESS Pin
ateece7-Mar-07 11:25
ateece7-Mar-07 11:25 
GeneralThanks a lot Pin
davepermen22-Feb-07 3:03
davepermen22-Feb-07 3:03 
QuestionSQL Server 2000 Database comparision Pin
Lokanatha.Reddy19-Dec-06 20:37
Lokanatha.Reddy19-Dec-06 20:37 
AnswerRe: SQL Server 2000 Database comparision Pin
ateece19-Dec-06 22:15
ateece19-Dec-06 22:15 
GeneralUsing the code. Pin
sp8ts3-Dec-06 14:47
sp8ts3-Dec-06 14:47 
GeneralRe: Using the code. Pin
ateece3-Dec-06 23:54
ateece3-Dec-06 23:54 
GeneralInner circle (clip region) is not smooth Pin
TomWork28-Sep-06 5:52
TomWork28-Sep-06 5:52 
GeneralRe: Inner circle (clip region) is not smooth Pin
ateece28-Sep-06 8:14
ateece28-Sep-06 8:14 
GeneralRe: Inner circle (clip region) is not smooth Pin
TomWork9-Oct-06 5:07
TomWork9-Oct-06 5:07 
GeneralRe: Inner circle (clip region) is not smooth Pin
ateece9-Oct-06 6:26
ateece9-Oct-06 6:26 
GeneralRe: Inner circle (clip region) is not smooth Pin
SDragon4214-Jun-07 5:39
SDragon4214-Jun-07 5:39 
GeneralASP.Net Pin
SSirica28-Sep-06 3:23
SSirica28-Sep-06 3:23 
AnswerRe: ASP.Net Pin
ateece28-Sep-06 8:09
ateece28-Sep-06 8:09 
GeneralRe: ASP.Net Pin
SSirica28-Sep-06 8:29
SSirica28-Sep-06 8:29 
GeneralRe: ASP.Net Pin
ateece28-Sep-06 9:12
ateece28-Sep-06 9:12 
GeneralRe: ASP.Net Pin
SSirica28-Sep-06 9:16
SSirica28-Sep-06 9:16 

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.