Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

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

, 16 Aug 2005
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
smartclientsoa_src.zip
SmartClient
Client
SMI.App
Controls
Forms
Modules
Properties
app.manifest
Settings.settings
Resources
240.png
Bottom.png
BuilderDialog_delete.bmp
DarkBlue.bmp
download-xp.gif
Earth.png
fldropen.png
iSync.gif
Leonardo_da_Vinci_My_Computer.png
LightBlue.bmp
LoginBox.jpg
LoginButton.jpg
LoginButton1.jpg
LoginButton2.jpg
Logo1.png
LogoPic.jpg
Middle.png
Refresh.bmp
refresh.ico
refresh1.ico
RightArrow.bmp
SuccessComplete.bmp
Task.bmp
Tasks.png
Top.png
TurnOffButton.bmp
wi0062-32.ico
wi0063-32.ico
wi0064-16.ico
wi0064-32.ico
SmartInstitute.App.csproj.user
wi0064-32.ico
SMI.Automation
Commands
Course
Framework
Security
Students
UI
Controls
Documents
MiscDocuments
StudentDocuments
Factories
Forms
Helpers
Misc
Properties
Settings.settings
Resources
BuilderDialog_delete.bmp
LogoSmall.bmp
Misho.jpg
My Pic 7.jpg
table.ico
SmartInstitute.Automation.csproj.user
Web References
SmartInstituteServices.AccountService
Account.datasource
AccountService.disco
AccountService.wsdl
Reference.map
SmartInstituteServices.CourseService
Course.datasource
CourseService.disco
CourseService.wsdl
Reference.map
SmartInstituteServices.SecurityService
Reference.map
SecurityService.disco
SecurityService.wsdl
SmartInstituteServices.StudentService
Reference.map
Student.datasource
StudentService.disco
StudentService.wsdl
SMI.ObjectModel.Enhanced
Base
Models
Properties
Settings.settings
Settings
SmartInstitute.ObjectModel.csproj.user
UMS.ObjectModel.Enhanced.csproj.user
SMI.Objects
SmartInstitute.csproj.user
CodeSmith
Tier
BusinessLogicLayer
Entity.cst
EntityBase.cst
EntityCollection.cst
EntityCollectionBase.cst
Enum.cst
IEntity.cst
DataAccessLayer
App.config.cst
CommonSql.cst
Configuration.cst
DBConcurrencyException.cst
DBException.cst
Factories
EntityRepositoryFactory.cst
IEntityRepository.cst
SqlClient
CVS
Entries
Entries.Extra
Entries.Extra.Old
Entries.Old
Repository
Root
TortoiseCVS.Status
SqlEntityRepository.cst
SqlEntityRepositoryBase.cst
TransactionManager.cst
UnitTests
EntityRepositoryTest.cst
WebServiceClient
WsEntityRepository.cst
WsEntityRepositoryBase.cst
Main.cst
nant.cst
References
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
StoredProcedures.cst
vsnet2003.project.cst
vsnet2003.solution.cst
vsnet2005.project.cst
vsnet2005.solution.cst
WebService
Web.config.cst
WebService.cst
Database
SmartInstitute.bak
Library
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
nunit.core.dll
nunit.framework.dll
Server
BLL
SmartInstitute.csproj.user
DAL
Factories
SmartInstitute.DataAccessLayer.csproj.user
SqlClient
Utilities
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
UnitTests
SmartInstitute.build
SmartInstitute.Facade
FacadeTest
SmartInstitute.Facade.csproj.user
SmartInstitute.Test
App.ico
SmartInstitute.Test.csproj.user
SmartInstituteServices
Global.asax
log
SmartInstituteServices.csproj.webinfo
SQL
Setup
SecurityDatabase
SecurityDatabaseConsole
App.ico
SecurityDatabaseConsole.exe.manifest
SR.strings
Tests
Tools.SecurityDatabaseConsole.csproj.user
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace SmartInstitute.Client.Automation.Controls
{
	[Description("Color Progress Bar")]
	[ToolboxBitmap(typeof(ProgressBar))]
	//[Designer(typeof(ColorProgressBarDesigner))]
	public class ColorProgressBar : System.Windows.Forms.Control
	{	
	
		//
		// set default values
		//
		private int _Value = 0;
		private int _Minimum = 0;
		private int _Maximum = 100;
		private int _Step = 10;
        private Timer timer;

        private FillStyles _FillStyle = FillStyles.Dashed;

		private Color _BarColor = Color.FromArgb(255, 128, 128);
		private Color _BorderColor = Color.Black;

		public enum FillStyles
		{
			Solid,
			Dashed
		}

		public ColorProgressBar()
		{
			base.Size = new Size(150, 15);
			SetStyle(
				ControlStyles.AllPaintingInWmPaint |
				ControlStyles.ResizeRedraw |
				ControlStyles.OptimizedDoubleBuffer,
				true
				);
		}

		[Description( "ColorProgressBar color")]
		[Category( "ColorProgressBar" )]
		public Color BarColor
		{
			get
			{
				return _BarColor;
			}
			set
			{
				_BarColor = value;
				this.Invalidate();
			}
		}

		[Description( "ColorProgressBar fill style")]
		[Category( "ColorProgressBar" )]
		private FillStyles FillStyle
		{
			get
			{
				return _FillStyle;
			}
			set
			{
				_FillStyle = value;
				this.Invalidate();
			}
		}

		[Description( "The current value for the ColorProgressBar, "+
			 "in the range specified by the Minimum and Maximum properties." )]
		[Category( "ColorProgressBar" )]
		// the rest of the Properties windows must be updated when this peroperty is changed.
		[RefreshProperties(RefreshProperties.All)]
		public int Value
		{
			get
			{
				return _Value;
			}
			set
			{
				if (value < _Minimum)
				{
					throw new ArgumentException("'"+value+"' is not a valid value for 'Value'.\n"+
						"'Value' must be between 'Minimum' and 'Maximum'.");
				}

				if (value > _Maximum)
				{
					throw new ArgumentException("'"+value+"' is not a valid value for 'Value'.\n"+
						"'Value' must be between 'Minimum' and 'Maximum'.");
				}

				_Value = value;			
				this.Invalidate();
			}
		}
		
		[Description("The lower bound of the range this ColorProgressbar is working with.")]
		[Category("ColorProgressBar")]
		[RefreshProperties(RefreshProperties.All)]
		public int Minimum
		{
			get
			{
				return _Minimum;
			}
			set
			{
				_Minimum = value;

				if (_Minimum > _Maximum)
					_Maximum = _Minimum;
				if (_Minimum > _Value)
					_Value = _Minimum;

				this.Invalidate();
			}
		}

		[Description("The uppper bound of the range this ColorProgressbar is working with.")]
		[Category("ColorProgressBar")]
		[RefreshProperties(RefreshProperties.All)]
		public int Maximum
		{
			get
			{
				return _Maximum;
			}
			set
			{
				_Maximum = value;

				if (_Maximum < _Value)
					_Value = _Maximum;
				if (_Maximum < _Minimum)
					_Minimum = _Maximum;

				this.Invalidate();
			}
		}

		[Description("The amount to jump the current value of the control by when the Step() method is called.")]
		[Category("ColorProgressBar")]		
		public int Step
		{
			get
			{
				return _Step;
			}
			set
			{
				_Step = value;
				this.Invalidate();
			}
		}

		[Description("The border color of ColorProgressBar")]
		[Category("ColorProgressBar")]		
		public Color BorderColor
		{
			get
			{
				return _BorderColor;
			}
			set
			{
				_BorderColor = value;
				this.Invalidate();
			}
		}
		
		//
		// Call the PerformStep() method to increase the value displayed by the amount set in the Step property
		//
		public void PerformStep()
		{
			if (_Value < _Maximum)
				_Value += _Step;
			else
				_Value = _Maximum;

			this.Invalidate();
		}
        private void t_Tick(object sender, EventArgs e)
        {
            this.PerformStep();
            
            if ( this.Value == this.Maximum)
            {
                this.Value = 0;
            }            
        }

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

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

        public void Stop()
        {
            if (null != timer)
            {

                timer.Stop();
                timer.Enabled = false;

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

                timer = null;
            }
        }

        //
		// Call the PerformStepBack() method to decrease the value displayed by the amount set in the Step property
		//
		public void PerformStepBack()
		{
			if (_Value > _Minimum)
				_Value -= _Step;
			else
				_Value = _Minimum;

			this.Invalidate();
		}

		//
		// Call the Increment() method to increase the value displayed by an integer you specify
		// 
		public void Increment(int value)
		{
			if (_Value < _Maximum)
				_Value += value;
			else
				_Value = _Maximum;

			this.Invalidate();
		}
		
		//
		// Call the Decrement() method to decrease the value displayed by an integer you specify
		// 
		public void Decrement(int value)
		{
			if (_Value > _Minimum)
				_Value -= value;
			else
				_Value = _Minimum;

			this.Invalidate();
		}
		
		protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
		{
			//
			// Calculate matching colors
			//
			Color darkColor = ControlPaint.Dark(_BarColor);
			Color bgColor = Color.White;//ControlPaint.Dark(_BarColor);

			//
			// Fill background
			//
			SolidBrush bgBrush = new SolidBrush(bgColor);

			// The region of the progress bar!
			int leftbar = 1;
			int topbar = 1;
			int X = this.Width-1;
			int Y = this.Height-1;
			Point[] points = {   new Point(leftbar + 2, topbar), 
								 new Point(X-2, topbar), 
								 new Point(X-1, topbar + 1), 
								 new Point(X, topbar + 2), 
								 new Point(X, Y-3), 
								 new Point(X-1, Y-2), 
								 new Point(X-2, Y-1), 
								 new Point(leftbar + 2, Y), 
								 new Point(leftbar + 1, Y-2), 
								 new Point(leftbar, Y-3), 
								 new Point(leftbar, topbar + 2),
								 new Point(leftbar + 1, topbar + 1),
			};    
			GraphicsPath path = new GraphicsPath();
			path.AddLines(points);

			Region reg = new Region(path);
			e.Graphics.FillRegion(Brushes.White, reg); //bgBrush
			bgBrush.Dispose();
			
			// 
			// Check for value
			//
			if (_Maximum == _Minimum || _Value == 0)
			{
				// Draw border only and exit;
				drawBorder(e.Graphics);
				return;
			}

			//
			// The following is the width of the bar. This will vary with each value.
			//
			int fillWidth = (this.Width * _Value) / (_Maximum - _Minimum);
			
			//
			// GDI+ doesn't like rectangles 0px wide or high
			//
			if (fillWidth == 0)
			{
				// Draw border only and exit;
				drawBorder(e.Graphics);
				return;
			}

			//Make the bars of the progress complete, just like XP bars
			if(fillWidth%8 != 0)
			{
				int rest = fillWidth % 8;
				fillWidth += (8-rest);
			}

			//
			// Rectangles for upper and lower half of bar
			//
			Rectangle chunkbar = new Rectangle(3,2, fillWidth, this.Height-4);
			//Rectangle topRect = new Rectangle(0, 0, fillWidth, this.Height / 2);
			//Rectangle buttomRect = new Rectangle(0, this.Height / 2, fillWidth, this.Height / 2);

			//
			// The gradient brush
			//
			LinearGradientBrush brush;			

			//
			// Paint upper half
			//
			brush = new LinearGradientBrush(chunkbar, Color.White, _BarColor, 90.0f);
			float[] relativeIntensities = {0.1f, 1.0f, 1.0f, 1.0f, 1.0f, 0.85f, 0.1f}; 
			float[] relativePositions =   {0.0f, 0.2f, 0.5f, 0.5f, 0.5f, 0.8f, 1.0f};

			// create a Blend object and assign it to silverBrush07
			Blend blend = new Blend();
			blend.Factors = relativeIntensities;
			blend.Positions = relativePositions; 
			brush.Blend = blend;

			e.Graphics.FillRectangle(brush, chunkbar);
			brush.Dispose();

			//
			// Calculate separator's setting
			//
			// Separator is made smaller like the XP progress
			int sepWidth = 8;//(int)(this.Height * .67);
			int sepCount = (int)(fillWidth / sepWidth);
			//Color sepColor = ControlPaint.LightLight(_BarColor);
			Color sepColor = Color.White;//ControlPaint.Dark(_BarColor);

			//
			// Paint separators
			//
			switch (_FillStyle)
			{
				case FillStyles.Dashed:
					// Draw each separator line
					for (int i = 0; i <= sepCount; i++)
					{
						e.Graphics.DrawLine(new Pen(sepColor, 2),
							sepWidth * i+3, 0, sepWidth * i+3, this.Height);
					}
					break;

				case FillStyles.Solid:
					// Draw nothing
					break;

				default:
					break;
			}

			//
			// Draw border and exit
			//
			drawBorder(e.Graphics);
		}

		//
		// Draw border
		//
		protected void drawBorder(Graphics g)
		{
			// additions by DDISoft
			int X = this.ClientRectangle.Width;
			int Y = this.ClientRectangle.Height;
			Point[] points = {   new Point(1, 2), 
								 new Point(2, 1), 
								 new Point(3, 0), 
								 new Point(X-4, 0), 
								 new Point(X-3, 1), 
								 new Point(X-2, 2), 
								 new Point(X-2, Y-3), 
								 new Point(X-3, Y-2), 
								 new Point(X-4, Y-1), 
								 new Point(3, Y-1), 
								 new Point(2, Y-2),
								 new Point(1, Y-3),
								 new Point(1, 2), 
			};  
      
			Point[] points2 = {  new Point(2, 2), 
								 new Point(3, 1), 
								 new Point(4, 1), 
								 new Point(X-5, 1), 
								 new Point(X-4, 1), 
								 new Point(X-3, 2), 
			};  
		
			g.DrawCurve(new Pen(Brushes.Gray, 1), points, 0);
			g.DrawCurve(new Pen(Brushes.LightGray, 1), points2, 0);
			g.DrawLine(new Pen(Brushes.LightGray, 1),2,2,2,Y-3);

			//Old original code
			/*Rectangle borderRect = new Rectangle(0, 0,
				ClientRectangle.Width - 1, ClientRectangle.Height - 1);
			g.DrawRectangle(new Pen(_BorderColor, 1), borderRect);*/
		}
	}
}

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

Share

About the Author


| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 17 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid