Click here to Skip to main content
13,287,568 members (54,533 online)
Click here to Skip to main content
Add your own
alternative version


52 bookmarked
Posted 29 Sep 2004

Gradient-Animation Waiting-Bar control

, 29 Sep 2004
Rate this:
Please Sign up or sign in to vote.
When processing is taking a long time, this control is very useful for informing the user.

Sample image - GradientAnimation-WaitBar.jpg


This article demonstrates a Gradient-Waiting-Bar control in C#. This control animates the gradient-image combined by FradientColor1, GradientColor2 infinitely. When any processing (working) is taking a long time, this control is very useful for informing user that current thread is now processing the work. This control does not use Win32 API, just uses C# functions.

Code listing

Following code is the GradientWaitingBar class:

Header of This control

// This control is Gradient Waiting Bar.
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Diagnostics;


This control has the following properties:

  • Speed Scrolling speed of control.
  • GradientColor1 Start color of gradient.
  • GradientColor2 End color of gradient.
  • ScrollWay Direction of scrolling gradient.
  • Interval Timer interval of scrolling gradient.
#region "Properties"
// property of timer
[System.ComponentModel.Description("Gets or sets " + 
 "the Interval of timer tick count for Speed of GradientWaitingBar"), 
public int Interval
    get    {
        return m_timer.Interval;
    set    {
        m_timer.Interval = value;

// property of speed in scrolling.
[System.ComponentModel.Description("Gets or sets the " + 
 "speed of gradient for GradientWaitingBar"), 
public int Speed
        return m_nSpeed;
        m_nSpeed = value;
// property of begin color in linear gradient
[System.ComponentModel.Description("Gets or sets the starting" + 
 " color of the gradient for GradientWaitingBar"), 
public Color GradientColor1
        return m_col1;
        m_col1 = value;

// property of end color in linear gradient
[System.ComponentModel.Description("Gets or sets the ending " + 
 "color of the gradient for GradientWaitingBar"), 
public Color GradientColor2
        return m_col2;
        m_col2 = value;

// property of scrolling direction in control
[System.ComponentModel.Description("Gets or sets" + 
  " the direction of scrolling the gradient"), 
        return m_nScrollway;
        m_nScrollway = value;


This control makes a Gradient Bitmap for performance. For making the Gradient Bitmap, this code uses C# code, not Win32 API.

// Make a Gradient Bitmap
// For performance, on sizing and changed Properties
// first makes a suitable bitmap image of gradient
// and then On paint this control uses it.
private void MakeBitmapForWaitingBar()
  //check the windows size
  if(this.ClientRectangle.Width == 0 || this.ClientRectangle.Height == 0)
  if(m_bitmap != null)
  Graphics gimage = null, gWnd = null;
  Brush br1, br2;
  Rectangle rt1, rt2;
  // Get temporary DC and make a compatible bitmap with current Windows.
  gWnd = Graphics.FromHwnd(this.Handle);
  m_bitmap = new Bitmap(this.ClientRectangle.Width, 
                 this.ClientRectangle.Height, gWnd);
      rt1 = this.ClientRectangle;
      rt1.Width = this.ClientRectangle.Width/2+1;
      rt2 = rt1;
      rt2.X = this.ClientRectangle.Width/2;
      rt2.Width = this.ClientRectangle.Width/2+1;
      br1 = new LinearGradientBrush(rt1, m_col1, m_col2, 
      br2 = new LinearGradientBrush(rt2, m_col2, m_col1, 
      rt1 = this.ClientRectangle;
      rt1.Height = this.ClientRectangle.Height/2 + 1;
      rt2 = rt1;
      rt2.Y = this.ClientRectangle.Height / 2;
      rt2.Height = this.ClientRectangle.Height/2 + 1;
      br1 = new LinearGradientBrush(rt1, m_col1, m_col2, 
      br2 = new LinearGradientBrush(rt2, m_col2, m_col1, 
  // make a new bitmap
  gimage = Graphics.FromImage(m_bitmap);
  gimage.FillRectangle(br2, rt2);
  gimage.FillRectangle(br1, rt1);

How to use it

You can develop it to serve your ideas. You can rewrite the above code as well, such as write alignment, border style and so on. If you want to use this control, it is very easy. The code is shown below:

using KDHLib.Controls.GradientWaitingBar;

public class Form1 : System.Windows.Forms.Form
    private System.ComponentModel.IContainer components;
    private KDHLib.Controls.GradientWaitingBar m_bar = null;
    public Form1()
        this.m_bar = new KDHLib.Controls.GradientWaitingBar();
        this.m_bar.BackColor = System.Drawing.Color.White;
        // set the gradient colors
        this.m_bar.GradientColor1 = System.Drawing.Color.LightPink;
        this.m_bar.GradientColor2 = System.Drawing.Color.GhostWhite;
        this.m_bar.Interval = 100;
        this.m_bar.Location = new System.Drawing.Point(384, 16);
        // Make a vertical Gradient scrolling bar
        this.m_bar.ScrollWAY = 
        this.m_bar.Size = new System.Drawing.Size(16, 144);
        // set the speed
        this.m_bar.Speed = 5;
        this.m_bar.TabIndex = 0;


It is a very simple control but it is very useful, I think. Thanks a lot for reading this document.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Kyung DuckHyun
Software Developer (Senior)
Korea (Republic of) Korea (Republic of)
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionThreadsecure? Pin
dherrmann9-Nov-08 7:35
memberdherrmann9-Nov-08 7:35 
AnswerRe: Threadsecure? Pin
dherrmann3-Mar-11 3:11
memberdherrmann3-Mar-11 3:11 
GeneralKyung DuckHyun Code Licensing Question... Pin
plexar17-Sep-07 11:48
memberplexar17-Sep-07 11:48 
GeneralRe: Kyung DuckHyun Code Licensing Question... Pin
Kyung DuckHyun17-Sep-07 17:46
memberKyung DuckHyun17-Sep-07 17:46 
QuestionHelp Pin
singhswat30-Jan-06 20:28
membersinghswat30-Jan-06 20:28 
NewsOff Color Bar at Some Widths Pin
Thomas Wells28-Dec-05 8:34
memberThomas Wells28-Dec-05 8:34 
GeneralRe: Off Color Bar at Some Widths Pin
Thomas Wells28-Dec-05 8:54
memberThomas Wells28-Dec-05 8:54 
GeneralJust what I needed! Pin
kruff4-Nov-05 11:26
memberkruff4-Nov-05 11:26 
QuestionProblem Pin
Carpetafhf27-Oct-05 1:38
memberCarpetafhf27-Oct-05 1:38 
GeneralMissing Dispose method Pin
Jay Alman20-Jan-05 7:21
memberJay Alman20-Jan-05 7:21 
GeneralRe: Missing Dispose method Pin
Kyung DuckHyun24-Oct-05 1:45
memberKyung DuckHyun24-Oct-05 1:45 
Questionprogress in form? Pin
Jonte20-Jan-05 5:01
memberJonte20-Jan-05 5:01 
GeneralMDI APP Pin
Iup3Barb25-Nov-04 0:49
memberIup3Barb25-Nov-04 0:49 
GeneralRe: MDI APP Pin
Kyung DuckHyun28-Nov-04 15:46
memberKyung DuckHyun28-Nov-04 15:46 
QuestionCredit? Pin
Brian Nottingham30-Sep-04 7:27
memberBrian Nottingham30-Sep-04 7:27 
AnswerRe: Credit? Pin
Kyung DuckHyun30-Sep-04 15:34
memberKyung DuckHyun30-Sep-04 15:34 
GeneralLooks very pretty Pin
Vladimir Afanasyev30-Sep-04 2:07
memberVladimir Afanasyev30-Sep-04 2:07 
GeneralRe: Looks very pretty Pin
Kyung DuckHyun4-Oct-04 23:27
memberKyung DuckHyun4-Oct-04 23:27 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171207.1 | Last Updated 30 Sep 2004
Article Copyright 2004 by Kyung DuckHyun
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid