Click here to Skip to main content
Licence CPOL
First Posted 18 Jul 2006
Views 134,504
Downloads 3,566
Bookmarked 189 times

SQL Server 2005 Circular Progress Bar

By | 26 Sep 2006 | Article
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)

About the Author

ateece

Architect
eNate Ltd
United Kingdom United Kingdom

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionHow to add and make use of control in existing project PinmemberGary613:50 27 Sep '11  
AnswerRe: How to add and make use of control in existing project Pinmemberateece1:36 3 Oct '11  
QuestionCannot post SpinningProgress object to a VIsual Studio 2008 visual basic application Pinmemberspicture4:51 3 Sep '11  
AnswerRe: Cannot post SpinningProgress object to a VIsual Studio 2008 visual basic application Pinmemberateece22:08 4 Sep '11  
GeneralMy vote of 5 PinmemberSaumitra Kumar Paul22:40 9 Jul '11  
GeneralExcellent post Pinmembervatsag23:39 9 Feb '11  
GeneralExcellent control! PinmemberFritz4414:39 26 Jan '11  
GeneralJust what i was looking for Pinmemberstrogg9:13 9 Oct '09  
GeneralWill not show/hide properly PinmemberMember 32699395:37 25 Sep '09  
GeneralThanks PinmemberGlimmerMan9:49 9 Mar '09  
GeneralAssembly generation failed -- Referenced assembly 'SpinningProgress' does not have a strong name Pinmemberblizznet8:37 26 Feb '09  
QuestionTransparent background ? Pinmemberyfrechette8:06 26 Nov '08  
GeneralThis is Excellent PinmemberMember 445279610:02 20 Oct '08  
GeneralQuestion about threading. PinmemberRash10106:44 18 Aug '08  
GeneralRe: Question about threading. Pinmemberateece2:51 19 Aug '08  
GeneralCannot get this working using Multithreading PinmemberSK2008VB5:12 25 Jun '08  
GeneralRe: Cannot get this working using Multithreading Pinmemberateece23:46 26 Jun '08  
GeneralExcellent Pinmembergnixon6:52 29 May '08  
GeneralI got stuck on multithreading.............. PinmemberAshStuff0:03 29 Apr '08  
GeneralRe: I get stuck on multithreading.............. Pinmemberateece0:09 29 Apr '08  
QuestionSlight Problem? PinmemberTraderJack23:36 14 Feb '08  
AnswerRe: Slight Problem? Pinmemberateece2:36 15 Feb '08  
GeneralRe: Slight Problem? PinmemberTraderJack10:13 15 Feb '08  
GeneralRe: Slight Problem? Pinmemberateece10:15 15 Feb '08  
GeneralPermission to use in my programm Pinmemberacosano10:28 2 Jan '08  

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.

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