Click here to Skip to main content
14,979,206 members
Articles / Multimedia / GDI+
Article
Posted 4 Sep 2013

Tagged as

Stats

55.6K views
5.2K downloads
51 bookmarked

Win8ProgressRing Control

Rate me:
Please Sign up or sign in to vote.
4.97/5 (30 votes)
27 Mar 2015CPOL4 min read
This article presents a user-drawn control, named Win8ProgressRing that mimics the Windows 8 Progress Ring.

 

Introduction Table of Contents

  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

 

Visual Properties Table of Contents

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 Table of Contents

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.
C#
// ********************* 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:

C#
public void Pulse ( )

 

Implementation Table of Contents

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

C#
// *********************************************** 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.

C#
// ************************************ 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 Table of Contents

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 Table of Contents

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

 

References Table of Contents

 

Development Environment Table of Contents

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 Table of Contents

09/03/2013   Original Article
03/27/2015   Added Demonstration Executable download; performed minor editing; regenerated Table of Contents with the Auto-TOC Generator

License

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

Share

About the Author

gggustafson
Software Developer (Senior)
United States United States
In 1964, I was in the US Coast Guard when I wrote my first program. It was written in RPG (note no suffixing numbers). Programs and data were entered using punched cards. Turnaround was about 3 hours. So much for the "good old days!"

In 1970, when assigned to Washington DC, I started my MS in Mechanical Engineering. I specialized in Transportation. Untold hours in statistical theory and practice were required, forcing me to use the university computer and learn the FORTRAN language, still using punched cards!

In 1973, I was employed by the Norfolk VA Police Department as a crime analyst for the High Intensity Target program. There, I was still using punched cards!

In 1973, I joined Computer Sciences Corporation (CSC). There, for the first time, I was introduced to a terminal with the ability to edit, compile, link, and test my programs on-line. CSC also gave me the opportunity to discuss technical issues with some of the brightest minds I've encountered during my career.

In 1975, I moved to San Diego to head up an IR&D project, BIODAB. I returned to school (UCSD) and took up Software Engineering at the graduate level. After BIODAB, I headed up a team that fixed a stalled project. I then headed up one of the two most satisfying projects of my career, the Automated Flight Operations Center at Ft. Irwin, CA.

I left Anteon Corporation (the successor to CSC on a major contract) and moved to Pensacola, FL. For a small company I built their firewall, given free to the company's customers. An opportunity to build an air traffic controller trainer arose. This was the other most satisfying project of my career.

Today, I consider myself capable.

Comments and Discussions

 
Praisecomment Pin
Member 1215837621-Nov-15 21:36
MemberMember 1215837621-Nov-15 21:36 
GeneralRe: comment Pin
gggustafson22-Nov-15 5:25
professionalgggustafson22-Nov-15 5:25 
SuggestionDemo project doesn't run out of the box.... Pin
Johnny J.23-Mar-15 23:01
professionalJohnny J.23-Mar-15 23:01 
GeneralRe: Demo project doesn't run out of the box.... Pin
gggustafson24-Mar-15 1:54
professionalgggustafson24-Mar-15 1:54 
GeneralRe: Demo project doesn't run out of the box.... Pin
Johnny J.24-Mar-15 2:05
professionalJohnny J.24-Mar-15 2:05 
GeneralRe: Demo project doesn't run out of the box.... Pin
gggustafson24-Mar-15 2:20
professionalgggustafson24-Mar-15 2:20 
GeneralRe: Demo project doesn't run out of the box.... Pin
Johnny J.24-Mar-15 2:33
professionalJohnny J.24-Mar-15 2:33 
GeneralRe: Demo project doesn't run out of the box.... Pin
gggustafson27-Mar-15 8:36
professionalgggustafson27-Mar-15 8:36 
GeneralRe: Demo project doesn't run out of the box.... Pin
Johnny J.27-Mar-15 11:55
professionalJohnny J.27-Mar-15 11:55 
Questionmy vot of +5 Pin
abbaspirmoradi5-Dec-13 9:29
professionalabbaspirmoradi5-Dec-13 9:29 
AnswerRe: my vot of +5 Pin
gggustafson5-Dec-13 10:34
professionalgggustafson5-Dec-13 10:34 
GeneralMy vote of 5 Pin
JayantaChatterjee28-Nov-13 19:11
professionalJayantaChatterjee28-Nov-13 19:11 
GeneralRe: My vote of 5 Pin
gggustafson29-Nov-13 5:25
professionalgggustafson29-Nov-13 5:25 
SuggestionMy Vote 5, Visualstudiogallery Pin
Klaus Ruttkowski20-Nov-13 23:57
MemberKlaus Ruttkowski20-Nov-13 23:57 
GeneralRe: My Vote 5, Visualstudiogallery Pin
gggustafson21-Nov-13 2:13
professionalgggustafson21-Nov-13 2:13 
GeneralMy vote of 5 Pin
Athari5-Sep-13 11:14
MemberAthari5-Sep-13 11:14 
GeneralRe: My vote of 5 Pin
gggustafson5-Sep-13 11:53
professionalgggustafson5-Sep-13 11:53 
Questionnice Pin
BillW335-Sep-13 7:17
professionalBillW335-Sep-13 7:17 
AnswerRe: nice Pin
gggustafson5-Sep-13 10:55
professionalgggustafson5-Sep-13 10:55 
GeneralNice work Pin
One-T4-Sep-13 20:20
MemberOne-T4-Sep-13 20:20 
GeneralRe: Nice work Pin
gggustafson5-Sep-13 3:39
professionalgggustafson5-Sep-13 3:39 
GeneralMy vote of 5 Pin
Roberto Guerzoni4-Sep-13 20:19
professionalRoberto Guerzoni4-Sep-13 20:19 
GeneralRe: My vote of 5 Pin
gggustafson5-Sep-13 3:40
professionalgggustafson5-Sep-13 3:40 
GeneralMy vote of 5 Pin
patel_pratik4-Sep-13 19:25
Memberpatel_pratik4-Sep-13 19:25 
GeneralRe: My vote of 5 Pin
gggustafson5-Sep-13 3:40
professionalgggustafson5-Sep-13 3:40 

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.