Click here to Skip to main content
14,977,142 members
Articles / Multimedia / GDI+
Article
Posted 10 Sep 2013

Tagged as

Stats

20.8K views
1.4K downloads
24 bookmarked

Win8MarqueeProgressIndicator Control

Rate me:
Please Sign up or sign in to vote.
4.93/5 (13 votes)
5 Dec 2013CPOL4 min read
This article presents a user-drawn control, named Win8MarqueeProgressIndicator.

Introduction [^]

Win8 Marquee Progress Indicator Test Demonstration

This short article presents a control, named Win8MarqueeProgressIndicator, that was requested by a reader of Win8ProgressRing Control. Basically, this control flattens the Win8ProgressRing control.

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 Marquee Progress Indicator

The Win8MarqueeProgressIndicator control has two properties that form the user's visual image.

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_width by either dragging the control's resizing handles or by specifying the Control_Width property. After some computations, the control_height is set equal to the indicator_diameter.

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 Win8MarqueeProgressIndicator control has the following properties available to the developer:

Name       Description
         
Animate       Gets or sets a value indicating whether the control moves the indicators automatically. If true, the control moves the indicators without further intervention; if false, the control moves the indicators only when the Pulse method is invoked. The default value is true.
Control_Width       Gets or sets the width of the control. When changed, this property also causes other internal values for the control to be changed. The value supplied for Control_Width must be a multiple of 33 that is greater than or equal to 99 and less than or equal to 462. The default value is 462 pixels. When Control_Width changes, the following method is invoked.
C#
// ********************** adjust_control_dimensions_from_width

void adjust_control_dimensions_from_width ( int new_width )
    {

    indicator_diameter = round ( 
                             ( double ) new_width / 
                             ( double ) MAXIMUM_POSITIONS );

    control_width = indicator_diameter * MAXIMUM_POSITIONS;
    control_height = indicator_diameter;

    this.Width=control_width;
    this.Height = control_height;
    }
Indicator_Color       Gets or sets the color of the indicators in the Win8MarqueeProgressIndicator control. The default value is Color.White.
Refresh_Rate       Gets or sets 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 [^]

Win8 Marquee Progress Indicator Movement

The Win8MarqueeProgressIndicator 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_Width 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 rightward along the width of the control. At the far right, the indicators wrap around to the far left. Initially the indicators are centered within the control width.

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 rightward indicator, it is moved to the next allowed indicator position (i.e., the indicator in position 18 is moved to position 20). To the right of control center are positions that will cause the indicators to appear to be accelerating. When an indicator is moved to position 32, its next position will be 0. Now as the indicator moves rightward it should appear to decelerate.

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-- )
        {
        int     index;
        double  position;
        int     x;
        int     y;

        index = position_indices [ i ];

        if ( index >= POSITIONS )
            {
            index = 0;
            }
        position = positions [ index ];

        x = round ( position *
                    ( double ) indicator_diameter );
        y = 0;

        rectangle.Location = new Point ( x, y );
        rectangle.Size = new Size ( indicator_diameter,
                                    indicator_diameter );
        graphics.FillEllipse ( brush, rectangle );

        index++;
        position_indices [ i ] = index;
        }

    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 Win8MarqueeProgressIndicator control.

GraphicsBuffer has been included within the control.

Conclusion [^]

This article has presented a control that provides a Windows 8 style marquee progress indicator.

References [^]

Development Environment [^]

Win8MarqueeProgressIndicator 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/05/2013   Original Article

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

 
QuestionAnimation... Pin
SledgeHammer015-Dec-13 8:12
MemberSledgeHammer015-Dec-13 8:12 
AnswerRe: Animation... Pin
gggustafson5-Dec-13 8:44
professionalgggustafson5-Dec-13 8:44 
QuestionVery nice sir Pin
Sacha Barber5-Dec-13 2:59
mvaSacha Barber5-Dec-13 2:59 
AnswerRe: Very nice sir Pin
gggustafson5-Dec-13 4:08
professionalgggustafson5-Dec-13 4:08 
GeneralMy vote of 5 Pin
Paul_Williams16-Sep-13 1:38
MemberPaul_Williams16-Sep-13 1:38 
GeneralRe: My vote of 5 Pin
gggustafson16-Sep-13 6:37
professionalgggustafson16-Sep-13 6:37 
GeneralAwesome! Pin
Ravi Bhavnani11-Sep-13 7:30
professionalRavi Bhavnani11-Sep-13 7:30 
GeneralRe: Awesome! Pin
gggustafson11-Sep-13 10:51
professionalgggustafson11-Sep-13 10:51 

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.