Click here to Skip to main content
Click here to Skip to main content

Win8ProgressRing Control

, 5 Dec 2013
Rate this:
Please Sign up or sign in to vote.
This article presents a user-drawn control, named Win8ProgressRing that mimics the Windows 8 Progress Ring.

Introduction [^]

Win8 Progress Ring Test Demonstration

This short article presents a control, named Win8ProgressRing, that mimics the Windows 8 Progress Ring.

Only a brief discussion of its implementation will be provided. In the following discussions, properties that are specified by the developer are displayed in BoldMixedCase text. Variables, used internally by the software are displayed in italicized_lowercase text.

Table of Contents

The symbol [^] returns the reader to the top of the Table of Contents.

Visual Properties [^]

Win8 Progress Ring Properties

The Win8ProgressRing control has two properties that form the user's visual image. In the figure to the right, the control's boundary is drawn in red.

The developer specifies the control's top-left corner by dragging the control from the ToolBox to a position on the form. This position becomes ( 0, 0 ) in the control's graphic environment. The developer specifies the control_height by either dragging the control's resizing handles or by specifying the Control_Height property. The control_width is set equal to the control_height.

The indicator color defaults to white. To change the indicator color, the developer specifies the new color through the Indicator_Color property.

The control's background color is transparent and cannot be changed.

Control Properties [^]

The Win8ProgressRing control has the following properties available to the developer:

Name       Description
         
Animate       Gets or sets a value indicating whether the control rotates the indicators automatically. If true, the control animates the indicator rotation; if false, the control moves the indicators only when the Pulse method is invoked. The default value is true.
Control_Height       Gets or sets the height of the control. When changed, this property also causes other internal values for the control to be changed. The default value is 100 pixels.
// ********************* adjust_control_dimensions_from_height

void adjust_control_dimensions_from_height ( int new_height )
    {

    indicator_radius = round ( ( double ) new_height / 
                               ( double ) SIZE_FACTOR );
    indicator_diameter = 2 * indicator_radius;

    control_height = SIZE_FACTOR * indicator_radius;
    control_width = control_height;

    outer_radius = control_height / 2;
    inner_radius = outer_radius - indicator_diameter;

    indicator_center_radius = inner_radius + 
                              indicator_radius;

    this.Height = control_height;
    this.Width = control_width;
    }
Indicator_Color       Gets or sets the color of the indicators in the Win8ProgressRing control. The default value is Color.White.
Refresh_Rate       The time, in milliseconds, between movements of the indicators. The value must be greater than or equal to ten, and less than or equal to 200. The default is 100 milliseconds.

The Pulse method is used to rotate the indicators once each time it is invoked. Its signature is:

  public void Pulse ( )

Implementation [^]

Win8 Progress Ring Control Computations

The Win8ProgressRing control is a User-Drawn Control. Parts of the control are drawn when the control's OnPaint method is invoked.

The control's graphic is made up of two distinct graphic images: the background graphic and the indicator graphic.

Once drawn, the background graphic does not need to be redrawn unless Control_Height is changed. The indicator graphic must be redrawn when the background graphic is redrawn; when the animation changes the indicators' positions; or when the indicator color changes.

The control is made up of six circular indicators that travel around the center of the control. Initially the indicators are grouped together starting at 90 degrees.

Note
The control uses Windows coordinates with the x-axis values increasing to the right; y-axis values increasing downward; and angles measured counterclockwise from the x-axis.

Starting with the most clockwise indicator, it is moved 11.25 degrees clockwise. If the indicator ends up in the fast movement area of the control, on the next pass, it will be moved some multiple of 11.25 degrees.

The angular advance (11.25) was derived from the desire to have eight indicators displayed in a quadrant. This results in 32 indicators around the control. Dividing 360 by 32 yields the advance of 11.25 degrees.

Because the trigonometric functions Sine and Cosine are invoked at each indicator advance, two tables are generated at initialization that contain 1440 values of the trigonometric functions in increments of 0.25 degrees.

Each of the six indicators is an instance of the Indicator class.

    // *********************************************** class Indicator

    public class Indicator
        {
        double  degrees = 0.0;
        double  fast = 1.0;

        // ************************************************* Indicator

        public Indicator ( )
            {

            Degrees = 0.0;
            Fast = 1.0;
            }

        // ************************************************* Indicator

        public Indicator ( double  degrees )
            {

            Degrees = degrees;
            Fast = 1.0;
            }

        // *************************************************** Degrees

        public double Degrees
            {

            get
                {
                return ( degrees );
                }
            set
                {
                degrees = value;
                }
            }

        // ****************************************************** Fast

        public double Fast
            {

            get
                {
                return ( fast );
                }
            set
                {
                fast = value;
                }
            }

        } // class Indicator

Finally, draw_indicator_graphic is invoked each time the interval timer raises the elapsed event.

    // ************************************ draw_indicator_graphic

    void draw_indicator_graphic (  Graphics graphics )
        {
        Brush       brush = new SolidBrush ( Indicator_Color );
        Rectangle   rectangle = new Rectangle ( );

        for ( int i = ( MAXIMUM_INDICATORS - 1 ); 
                  ( i >= 0 ); 
                  i-- )
            {
            double  degrees = indicators [ i ].Degrees;
            int     dx;
            int     dy;

            if ( degrees < 0.0 )
                {
                degrees += 360.0;
                }

            dx = round ( ( double ) indicator_center_radius *
                         cos ( degrees ) ) +
                 indicator_center_radius;
            dy = indicator_center_radius -
                 round ( ( double ) indicator_center_radius *
                         sin ( degrees ) );

            rectangle.Location = new Point ( dx, dy );
            rectangle.Size = new Size ( indicator_diameter,
                                        indicator_diameter );
            graphics.FillEllipse ( brush, rectangle );

            degrees -= ( double ) indicators [ i ].Fast * 
                       INDICATOR_OFFSET;

            if ( indicators [ i ].Fast > 1.0 )
                {
                indicators [ i ].Fast += 0.25;
                }

            if ( degrees < 0.0 )
                {
                indicators [ i ].Fast = 1.25;
                }
            else if ( degrees < START_AT )
                {
                indicators [ i ].Fast = 1.0;
                }

            indicators [ i ].Degrees = degrees;
            }

        brush.Dispose ( );
        }

Graphics Buffer [^]

The GraphicsBuffer class contains an off-screen bitmap used to draw graphic objects without flicker. Although .Net provides a Double Buffered Graphics capability, it is overkill for the Win8ProgressRing control.

GraphicsBuffer has been included within the control.

Conclusion [^]

This article has presented a control that mimics the Windows 8 Progress Ring.

References [^]

Development Environment [^]

Win8ProgressRing control was developed in the following environment:

      Microsoft Windows 7 Professional Service Pack 1
      Microsoft Visual Studio 2008 Professional
      Microsoft .Net Framework Version 3.5 SP1
      Microsoft Visual C# 2008

History [^]

09/03/2013   Original Article

License

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

About the Author

gggustafson
Software Developer (Senior)
United States United States
I started programming more than 42 years ago using AutoCoder and RPG (note no suffixing numbers). Programs and data were entered using punched cards. Turnaround between submitting a job for compilation and execution was about 3 hours. So much for the "good old days!" Today, I particularly enjoy programming real-time software. I consider myself capable in WinForms, Mobile Apps, and C# although there are occasions that I yearn to return to C and the Win32 API.

Comments and Discussions

 
Questionmy vot of +5 Pinprofessionalabbaspirmoradi5-Dec-13 9:29 
AnswerRe: my vot of +5 Pinprofessionalgggustafson5-Dec-13 10:34 
GeneralMy vote of 5 PinmemberJayanta Chatterjee28-Nov-13 19:11 
GeneralRe: My vote of 5 Pinprofessionalgggustafson29-Nov-13 5:25 
SuggestionMy Vote 5, Visualstudiogallery [modified] PinmemberKlaus Ruttkowski20-Nov-13 23:57 
GeneralRe: My Vote 5, Visualstudiogallery Pinprofessionalgggustafson21-Nov-13 2:13 
GeneralMy vote of 5 PinprofessionalAthari5-Sep-13 11:14 
GeneralRe: My vote of 5 Pinmembergggustafson5-Sep-13 11:53 
Questionnice PinmemberCIDev5-Sep-13 7:17 
AnswerRe: nice Pinmembergggustafson5-Sep-13 10:55 
GeneralNice work PinmemberOne-T4-Sep-13 20:20 
GeneralRe: Nice work Pinmembergggustafson5-Sep-13 3:39 
GeneralMy vote of 5 PinmemberRoberto Guerzoni4-Sep-13 20:19 
GeneralRe: My vote of 5 Pinmembergggustafson5-Sep-13 3:40 
GeneralMy vote of 5 Pinmemberpatel_pratik4-Sep-13 19:25 
GeneralRe: My vote of 5 Pinmembergggustafson5-Sep-13 3:40 
GeneralMy vote of 5 Pinmemberhyblusea4-Sep-13 16:52 
GeneralRe: My vote of 5 Pinmembergggustafson4-Sep-13 18:29 
QuestionRequest PinprofessionalRavi Bhavnani4-Sep-13 10:49 
AnswerRe: Request Pinmembergggustafson4-Sep-13 13:10 
QuestionNice one! PinprofessionalRavi Bhavnani4-Sep-13 10:47 
AnswerRe: Nice one! Pinmembergggustafson4-Sep-13 13:09 

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 | Mobile
Web03 | 2.8.140721.1 | Last Updated 5 Dec 2013
Article Copyright 2013 by gggustafson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid