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

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
#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;

#endregion

namespace SmartInstitute.Client.Controls
{
	// Custom control that draws the caption for each pane. Contains an active 
	// state and draws the caption different for each state. Caption is drawn
	// with a gradient fill and antialias font.
	public class PaneCaption : UserControl
	{
		private class Consts
		{
			public const int DefaultHeight = 26;
			public const string DefaultFontName = "Tahoma";
			public const int DefaultFontSize = 12;
			public const int PosOffset = 4;
		}

		private bool m_active = false;
		private bool m_antiAlias = false;
		private bool m_allowActive = false;
		private string m_text = string.Empty;

		private Color m_colorActiveText = Color.Black;
		private Color m_colorInactiveText = Color.White;

		private Color m_colorActiveLow = Color.FromArgb(255, 165, 78);
		private Color m_colorActiveHigh = Color.FromArgb(255, 225, 155);
		private Color m_colorInactiveLow = Color.FromArgb(3, 55, 145);
		private Color m_colorInactiveHigh = Color.FromArgb(90, 135, 215);

		private SolidBrush m_brushActiveText;
		private SolidBrush m_brushInactiveText;
		private LinearGradientBrush m_brushActive;
		private LinearGradientBrush m_brushInactive;
		private StringFormat m_format = new StringFormat();

		private IContainer components = null;

		[CategoryAttribute("Appearance")]
		[DescriptionAttribute("If should draw the text as antialiased.")]
		[DefaultValueAttribute(true)]
		public bool AntiAlias
		{
			get
			{
				return m_antiAlias;
			}

			set
			{
				m_antiAlias = value;
				Invalidate();
			}
		}

		[DefaultValueAttribute(typeof(Color), "Black")]
		[DescriptionAttribute("Color of the text when active.")]
		[CategoryAttribute("Appearance")]
		public Color ActiveTextColor
		{
			get
			{
				return m_colorActiveText;
			}

			set
			{
				if (value == Color.Empty)
				{
					value = Color.Black;
				}
				m_colorActiveText = value;
				m_brushActiveText = new SolidBrush(m_colorActiveText);
				Invalidate();
			}
		}

		[CategoryAttribute("Appearance")]
		[DefaultValueAttribute(typeof(Color), "White")]
		[DescriptionAttribute("Color of the text when inactive.")]
		public Color InactiveTextColor
		{
			get
			{
				return m_colorInactiveText;
			}

			set
			{
				if (value == Color.Empty)
				{
					value = Color.White;
				}
				m_colorInactiveText = value;
				m_brushInactiveText = new SolidBrush(m_colorInactiveText);
				Invalidate();
			}
		}

		[DescriptionAttribute("Low color of the active gradient.")]
		[CategoryAttribute("Appearance")]
		[DefaultValueAttribute(typeof(Color), "255, 165, 78")]
		public Color ActiveGradientLowColor
		{
			get
			{
				return m_colorActiveLow;
			}

			set
			{
				if (value == Color.Empty)
				{
					value = Color.FromArgb(255, 165, 78);
				}
				m_colorActiveLow = value;
				CreateGradientBrushes();
				Invalidate();
			}
		}

		[CategoryAttribute("Appearance")]
		[DescriptionAttribute("High color of the active gradient.")]
		[DefaultValueAttribute(typeof(Color), "255, 225, 155")]
		public Color ActiveGradientHighColor
		{
			get
			{
				return m_colorActiveHigh;
			}

			set
			{
				if (value == Color.Empty)
				{
					value = Color.FromArgb(255, 225, 155);
				}
				m_colorActiveHigh = value;
				CreateGradientBrushes();
				Invalidate();
			}
		}

		[DefaultValueAttribute(typeof(Color), "3, 55, 145")]
		[DescriptionAttribute("Low color of the inactive gradient.")]
		[CategoryAttribute("Appearance")]
		public Color InactiveGradientLowColor
		{
			get
			{
				return m_colorInactiveLow;
			}

			set
			{
				if (value == Color.Empty)
				{
					value = Color.FromArgb(3, 55, 145);
				}
				m_colorInactiveLow = value;
				CreateGradientBrushes();
				Invalidate();
			}
		}

		[CategoryAttribute("Appearance")]
		[DescriptionAttribute("High color of the inactive gradient.")]
		[DefaultValueAttribute(typeof(Color), "90, 135, 215")]
		public Color InactiveGradientHighColor
		{
			get
			{
				return m_colorInactiveHigh;
			}

			set
			{
				if (value == Color.Empty)
				{
					value = Color.FromArgb(90, 135, 215);
				}
				m_colorInactiveHigh = value;
				CreateGradientBrushes();
				Invalidate();
			}
		}

		// brush used to draw the caption
		private SolidBrush TextBrush
		{
			get
			{
				if (m_active && m_allowActive)
					return m_brushActiveText;
				else
					return m_brushInactiveText;
			}
		}

		// gradient brush for the background
		private LinearGradientBrush BackBrush
		{
			get
			{
				if (m_active && m_allowActive)
					return m_brushActive;
				else
					return m_brushInactive;
			}
		}

		public override string Text
		{
			get
			{
				return Caption;
			}

			set
			{
				Caption = value;
			}
		}

		[DescriptionAttribute("Text displayed in the caption.")]
		[DefaultValueAttribute("")]
		[CategoryAttribute("Appearance")]
		public string Caption
		{
			get
			{
				return m_text;
			}

			set
			{
				m_text = value;
				Invalidate();
			}
		}

		[DescriptionAttribute("The active state of the caption, draws the caption with different gradient colors.")]
		[DefaultValueAttribute(false)]
		[CategoryAttribute("Appearance")]
		public bool Active
		{
			get
			{
				return m_active;
			}

			set
			{
				m_active = value;
				Invalidate();
			}
		}

		[DefaultValueAttribute(true)]
		[CategoryAttribute("Appearance")]
		[DescriptionAttribute("True always uses the inactive state colors, false maintains an active and inactive state.")]
		public bool AllowActive
		{
			get
			{
				return m_allowActive;
			}

			set
			{
				m_allowActive = value;
				Invalidate();
			}
		}

		public PaneCaption()
		{
			InitializeComponent();

			// set double buffer styles
			SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);

			// init the height
			Height = Consts.DefaultHeight;

			// format used when drawing the text
			m_format.FormatFlags = StringFormatFlags.NoWrap;
			m_format.LineAlignment = StringAlignment.Center;
			m_format.Trimming = StringTrimming.EllipsisCharacter;

			// init the font
			Font = new Font("Tahoma", 12.0F, FontStyle.Bold);

			// create gdi objects
			ActiveTextColor = m_colorActiveText;
			InactiveTextColor = m_colorInactiveText;

			// setting the height above actually does this, but leave
			// in incase change the code (and forget to init the 
			// gradient brushes)
			CreateGradientBrushes();
		}

		// the caption needs to be drawn
		protected override void OnPaint(PaintEventArgs e)
		{
			DrawCaption(e.Graphics);
			base.OnPaint(e);
		}

		// draw the caption
		private void DrawCaption(Graphics g)
		{
			// background
			g.FillRectangle(this.BackBrush, this.DisplayRectangle);

			if (m_antiAlias)
				g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

			// need a rectangle when want to use ellipsis
			RectangleF bounds = new RectangleF(Consts.PosOffset,
												0,
												this.DisplayRectangle.Width - Consts.PosOffset,
												this.DisplayRectangle.Height);

			g.DrawString(m_text, this.Font, this.TextBrush, bounds, m_format);
		}

		// clicking on the caption does not give focus,
		// handle the mouse down event and set focus to self
		protected override void OnMouseDown(MouseEventArgs e)
		{
			base.OnMouseDown(e);
			if (m_allowActive)
			{
				Focus();
			}
		}

		protected override void OnSizeChanged(EventArgs e)
		{
			base.OnSizeChanged(e);
			// create the gradient brushes based on the new size
			CreateGradientBrushes();
		}

		private void CreateGradientBrushes()
		{
			// can only create brushes when have a width and height
			if (Width > 0 && Height > 0)
			{
				if (m_brushActive != null)
				{
					m_brushActive.Dispose();
				}

				m_brushActive = new LinearGradientBrush(DisplayRectangle, m_colorActiveHigh, m_colorActiveLow, LinearGradientMode.Vertical);

				if (m_brushInactive != null)
				{
					m_brushInactive.Dispose();
				}

				m_brushInactive = new LinearGradientBrush(DisplayRectangle, m_colorInactiveHigh, m_colorInactiveLow, LinearGradientMode.Vertical);
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		[DebuggerStepThroughAttribute()]
		private void InitializeComponent()
		{
			this.Name = "PaneCaption";
			this.Size = new Size(150, 30);
		}
	}
}

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
Web03 | 2.8.140916.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