Click here to Skip to main content
15,883,921 members
Articles / Web Development / ASP.NET

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

Rate me:
Please Sign up or sign in to vote.
4.96/5 (134 votes)
16 Aug 200540 min read 1.2M   3.9K   462  
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace SmartInstitute.Client.Automation.Controls
{
	/// <summary>
	/// An XP style Activity Bar.
	/// </summary>
	public class ActivityBar : System.Windows.Forms.UserControl
	{
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private ColorBlend cb;
		private Timer t;
		private int tickCount;

		private Color _barColor = Color.Orange;
		/// <summary>
		/// Determines the main color for the activity bar
		/// </summary>
		[Description("Determines the main color for the activity bar."), 
		Category("Appearance")]
		public Color BarColor
		{
			get { return _barColor;}
			set 
			{
				_barColor = value; 
				ColorPropertyChanged();
			}
		}

		private Color _borderColor= SystemColors.ActiveBorder;
		/// <summary>
		/// Determines the color for the activity bar border
		/// </summary>
		[Description("Determines the color for the activity bar border."), 
		Category("Appearance")]
		public Color BorderColor
		{
			get { return _borderColor;}
			set 
			{
				_borderColor = value; 
				ColorPropertyChanged();
			}
		}

		private Color _highlightColor = Color.White;
		/// <summary>
		/// Determines the highlight color for the activity bar
		/// </summary>
		[Description("Determines the highlight color for the activity bar."), 
		Category("Appearance")]
		public Color HighlightColor
		{
			get { return _highlightColor;}
			set 
			{ 
				_highlightColor = value; 
				ColorPropertyChanged();
			}
		}

		/// <summary>
		/// Default constructor
		/// </summary>
		public ActivityBar()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
			// set double buffer styles
			SetStyle(ControlStyles.ResizeRedraw, true);
			SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			SetStyle(ControlStyles.UserPaint, true);
			SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
			SetStyle(ControlStyles.ContainerControl, true);
			SetStyle(ControlStyles.SupportsTransparentBackColor, true);

			this.BackColor = Color.Transparent;				
			UpdateStyles();
			
			BuildColorBlend();

			
		}

		private void BuildColorBlend()
		{
			cb = new ColorBlend(7);
			cb.Colors  = new Color[] {
										 _barColor, 
										 _barColor,
										 _barColor,
										 _highlightColor, 
										 _highlightColor, 
										 _barColor, 
										 _barColor};

			cb.Positions = new float[] {
										   0.0f, 
										   0.01f,
										   0.2f, 
										   0.4f, 
										   0.6f, 
										   0.8f, 
										   1.0f};
		}

		private void ColorPropertyChanged()
		{
			BuildColorBlend();
			this.Refresh();
		}

		/// <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 Component 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.SuspendLayout();
			// 
			// ActivityBar
			// 
			this.Name = "ActivityBar";
			this.Size = new System.Drawing.Size(440, 12);
			this.ResumeLayout(false);

		}
		#endregion

		protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			LinearGradientBrush lBrush = new LinearGradientBrush(this.ClientRectangle, Color.White, Color.Orange,
				LinearGradientMode.Horizontal);
			lBrush.InterpolationColors = cb;
			g.FillRectangle(lBrush, 1, 1, this.Width - 2, this.Height - 2);
			Brush b = new SolidBrush(_borderColor);
			Pen p = new Pen(b, 1);
			g.DrawRectangle(p, 0, 0, this.Width - 1, this.Height - 1);
			p.Dispose();
			b.Dispose();
			lBrush.Dispose();
		}

		protected override void OnPaintBackground(PaintEventArgs pevent)
		{
			// Make sure the background isn't erased, to reduce flicker

			//base.OnPaintBackground (pevent);
		}

		/// <summary>
		/// Performs the color rotation in the activity bar
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void t_Tick(object sender, EventArgs e)
		{
			// Each color segment gets "scrolled" 20 positions to the right
			// then the colors get moved to the right in the colorblend array
			// and the deltas reset
			if (++tickCount >= 20)
			{
				tickCount = 0;
				Color last = cb.Colors[6];
				for (int i = 6; i>0; i--)
				{
					cb.Colors[i] = cb.Colors[i-1];
				}
				cb.Colors[0] = last;
			}

			// get color advance delta
			float f = tickCount / 100.0f;

			// advance colors
			cb.Positions[1] = 0.01f + f;
			cb.Positions[2] = 0.2f + f;
			cb.Positions[3] = 0.4f + f;
			cb.Positions[4] = 0.6f + f;
			cb.Positions[5] = 0.8f + f;
			//redraw controls
			this.Refresh();   
		}

		public void Start()
		{
			if (null == t)
			{
				t = new Timer();
				t.Interval = 50;
				t.Tick += new EventHandler(t_Tick);

				t.Enabled = true;
				t.Start();
			}
		}

		public void Stop()
		{
			if (null != t)
			{
				t.Stop();
				t.Enabled = false;

				t.Tick -= new EventHandler(t_Tick);
				t.Dispose();

				t = null;
			}
		}
	}
}

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
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions