Click here to Skip to main content
11,576,060 members (55,454 online)
Click here to Skip to main content

SQL Server 2005 Circular Progress Bar

, 26 Sep 2006 CPOL 177.4K 7.9K 196
Rate this:
Please Sign up or sign in to vote.
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.

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.

'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 :-)

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.
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)

Share

About the Author

ateece
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.

You may also be interested in...

Comments and Discussions

 
Questionmemory leak Pin
polishz39-Feb-14 16:52
memberpolishz39-Feb-14 16:52 
AnswerRe: memory leak Pin
ateece10-Feb-14 7:06
memberateece10-Feb-14 7:06 
GeneralRe: memory leak Pin
polishz311-Feb-14 0:59
memberpolishz311-Feb-14 0:59 
QuestionUse like a progressbar Pin
ichilouch21-May-13 3:21
memberichilouch21-May-13 3:21 
GeneralGreat Work Pin
ALDER_MORIGGI10-Sep-12 23:25
memberALDER_MORIGGI10-Sep-12 23:25 
QuestionHow to add and make use of control in existing project Pin
Gary6127-Sep-11 3:50
memberGary6127-Sep-11 3:50 
AnswerRe: How to add and make use of control in existing project Pin
ateece3-Oct-11 1:36
memberateece3-Oct-11 1:36 
QuestionCannot post SpinningProgress object to a VIsual Studio 2008 visual basic application Pin
spicture3-Sep-11 4:51
memberspicture3-Sep-11 4:51 
AnswerRe: Cannot post SpinningProgress object to a VIsual Studio 2008 visual basic application Pin
ateece4-Sep-11 22:08
memberateece4-Sep-11 22:08 
GeneralMy vote of 5 Pin
Saumitra Kumar Paul9-Jul-11 22:40
memberSaumitra Kumar Paul9-Jul-11 22:40 
GeneralExcellent post Pin
vatsag9-Feb-11 23:39
membervatsag9-Feb-11 23:39 
GeneralExcellent control! Pin
Fritz4426-Jan-11 14:39
memberFritz4426-Jan-11 14:39 
GeneralJust what i was looking for Pin
strogg9-Oct-09 9:13
memberstrogg9-Oct-09 9:13 
GeneralWill not show/hide properly Pin
Member 326993925-Sep-09 5:37
memberMember 326993925-Sep-09 5:37 
GeneralThanks Pin
GlimmerMan9-Mar-09 9:49
memberGlimmerMan9-Mar-09 9:49 
GeneralAssembly generation failed -- Referenced assembly 'SpinningProgress' does not have a strong name Pin
blizznet26-Feb-09 8:37
memberblizznet26-Feb-09 8:37 
QuestionTransparent background ? Pin
yfrechette26-Nov-08 8:06
memberyfrechette26-Nov-08 8:06 
GeneralThis is Excellent Pin
Member 445279620-Oct-08 10:02
memberMember 445279620-Oct-08 10:02 
GeneralCannot get this working using Multithreading Pin
SK2008VB25-Jun-08 5:12
memberSK2008VB25-Jun-08 5:12 
GeneralRe: Cannot get this working using Multithreading Pin
ateece26-Jun-08 23:46
memberateece26-Jun-08 23:46 
GeneralExcellent Pin
gnixon29-May-08 6:52
membergnixon29-May-08 6:52 
GeneralI got stuck on multithreading.............. Pin
AshStuff29-Apr-08 0:03
memberAshStuff29-Apr-08 0:03 
GeneralRe: I get stuck on multithreading.............. Pin
ateece29-Apr-08 0:09
memberateece29-Apr-08 0:09 
QuestionSlight Problem? Pin
TraderJack14-Feb-08 23:36
memberTraderJack14-Feb-08 23:36 
AnswerRe: Slight Problem? Pin
ateece15-Feb-08 2:36
memberateece15-Feb-08 2:36 
GeneralRe: Slight Problem? Pin
TraderJack15-Feb-08 10:13
memberTraderJack15-Feb-08 10:13 
GeneralRe: Slight Problem? Pin
ateece15-Feb-08 10:15
memberateece15-Feb-08 10:15 
GeneralPermission to use in my programm Pin
acosano2-Jan-08 10:28
memberacosano2-Jan-08 10:28 
GeneralRe: Permission to use in my programm Pin
ateece2-Jan-08 22:52
memberateece2-Jan-08 22:52 
GeneralNice! Pin
KaosKidd11-Dec-07 8:20
memberKaosKidd11-Dec-07 8:20 
GeneralSlight modification Pin
Johnny J.1-Oct-07 3:49
memberJohnny J.1-Oct-07 3:49 
GeneralRe: Slight modification Pin
ateece1-Oct-07 11:42
memberateece1-Oct-07 11:42 
QuestionWhat's wrong? Pin
dherrmann24-Aug-07 13:39
memberdherrmann24-Aug-07 13:39 
AnswerRe: What's wrong? Pin
ateece29-Aug-07 22:30
memberateece29-Aug-07 22:30 
GeneralRe: What's wrong? Pin
dherrmann30-Aug-07 3:09
memberdherrmann30-Aug-07 3:09 
AnswerRe: What's wrong? Pin
ateece30-Aug-07 3:18
memberateece30-Aug-07 3:18 
You don't place threading as a single line thing. It is more of a concept. Worth looking into because it isnt as complicated in .Net as it is in other languages.

With regards the spinning progress, is the AutoIncrement property set to true? is the enabled property set to true?

Do you see the control spinning at design-time?
GeneralRe: What's wrong? Pin
dherrmann30-Aug-07 4:45
memberdherrmann30-Aug-07 4:45 
GeneralRe: What's wrong? Pin
ateece30-Aug-07 5:45
memberateece30-Aug-07 5:45 
GeneralI dont know how to use it Pin
weaselpt4-Jul-07 22:13
memberweaselpt4-Jul-07 22:13 
AnswerRe: I dont know how to use it Pin
ateece5-Jul-07 2:57
memberateece5-Jul-07 2:57 
GeneralRe: I dont know how to use it Pin
weaselpt6-Jul-07 7:40
memberweaselpt6-Jul-07 7:40 
GeneralCOOL Pin
Hypothalamus5-Jun-07 3:49
memberHypothalamus5-Jun-07 3:49 
QuestionMS ACCESS Pin
Floodguy6-Mar-07 19:23
memberFloodguy6-Mar-07 19:23 
AnswerRe: MS ACCESS Pin
ateece7-Mar-07 11:25
memberateece7-Mar-07 11:25 
GeneralThanks a lot Pin
davepermen22-Feb-07 3:03
memberdavepermen22-Feb-07 3:03 
QuestionSQL Server 2000 Database comparision Pin
Lokanatha.Reddy19-Dec-06 20:37
memberLokanatha.Reddy19-Dec-06 20:37 
AnswerRe: SQL Server 2000 Database comparision Pin
ateece19-Dec-06 22:15
memberateece19-Dec-06 22:15 
GeneralUsing the code. Pin
sp8ts3-Dec-06 14:47
membersp8ts3-Dec-06 14:47 
GeneralRe: Using the code. Pin
ateece3-Dec-06 23:54
memberateece3-Dec-06 23:54 
GeneralInner circle (clip region) is not smooth Pin
TomWork28-Sep-06 5:52
memberTomWork28-Sep-06 5:52 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 26 Sep 2006
Article Copyright 2006 by ateece
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid