Click here to Skip to main content
15,886,799 members
Articles / Desktop Programming / Windows Forms

XP like colour progress bar

Rate me:
Please Sign up or sign in to vote.
4.27/5 (18 votes)
30 Mar 20052 min read 80.3K   1.8K   35  
A WinForms progress bar control.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using ColorProgressBar;

namespace ColorProgressBarExample
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private ColorProgressBar.ColorProgressBar colorProgressBar2;
		private ColorProgressBar.ColorProgressBar colorProgressBar1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Timer timer2;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.colorProgressBar2 = new ColorProgressBar.ColorProgressBar();
			this.colorProgressBar1 = new ColorProgressBar.ColorProgressBar();
			this.timer2 = new System.Windows.Forms.Timer(this.components);
			this.SuspendLayout();
			// 
			// colorProgressBar2
			// 
			this.colorProgressBar2.BarColor = System.Drawing.Color.OrangeRed;
			this.colorProgressBar2.BorderColor = System.Drawing.Color.Black;
			this.colorProgressBar2.FillStyle = ColorProgressBar.ColorProgressBar.FillStyles.Dashed;
			this.colorProgressBar2.Location = new System.Drawing.Point(16, 64);
			this.colorProgressBar2.Maximum = 100;
			this.colorProgressBar2.Minimum = 0;
			this.colorProgressBar2.Name = "colorProgressBar2";
			this.colorProgressBar2.Size = new System.Drawing.Size(216, 40);
			this.colorProgressBar2.Step = 1;
			this.colorProgressBar2.TabIndex = 1;
			this.colorProgressBar2.Value = 100;
			// 
			// colorProgressBar1
			// 
			this.colorProgressBar1.BarColor = System.Drawing.Color.LimeGreen;
			this.colorProgressBar1.BorderColor = System.Drawing.Color.Black;
			this.colorProgressBar1.FillStyle = ColorProgressBar.ColorProgressBar.FillStyles.Dashed;
			this.colorProgressBar1.Location = new System.Drawing.Point(16, 16);
			this.colorProgressBar1.Maximum = 100;
			this.colorProgressBar1.Minimum = 0;
			this.colorProgressBar1.Name = "colorProgressBar1";
			this.colorProgressBar1.Size = new System.Drawing.Size(216, 40);
			this.colorProgressBar1.Step = 1;
			this.colorProgressBar1.TabIndex = 2;
			this.colorProgressBar1.Value = 0;
			// 
			// timer2
			// 
			this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.Color.White;
			this.ClientSize = new System.Drawing.Size(384, 126);
			this.Controls.Add(this.colorProgressBar1);
			this.Controls.Add(this.colorProgressBar2);
			this.Name = "Form1";
			this.Text = "Example";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			
 
			// Sets the timer interval to 5 seconds.
			timer2.Interval = 100;
			timer2.Start();
		}

		private void timer2_Tick(object sender, System.EventArgs e)
		{
			colorProgressBar1.PerformStep();
			if (colorProgressBar1.Value == colorProgressBar1.Maximum)
			{
				colorProgressBar1.Value = 0;
			}
			colorProgressBar2.PerformStepBack();
			if (colorProgressBar1.Value == colorProgressBar1.Minimum)
			{
				colorProgressBar2.Value = 100;
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Bulgaria Bulgaria
Software engineer for TeamR3 Bulgaria.

Comments and Discussions