Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads
 
Add your own
alternative version

Unleash PropertyGrid with Dynamic Properties and Globalization

, 29 Jan 2004 CPOL
The article presents a way to enhance the use of the PropertyGid control with dynamic properties and globalization
using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using CustomControls.Enumerations;

namespace CustomControls.Win32Controls
{

	public class CTextBox:TextBox
	{
		#region "Variables"

		CustomControls.Enumerations.State _State=CustomControls.Enumerations.State.Normal;

		#endregion

		#region "Properties"

		protected State State
		{
			get{return _State;}
			set
			{
				if(value!=_State)
				{
					_State= value;
					Invalidate();
				}
			}
		}

		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public new  BorderStyle BorderStyle
		{
			get{return BorderStyle.FixedSingle;}
		}

		#endregion

		#region "Constructor"
		
		public CTextBox()
		{
			base.BorderStyle=BorderStyle.FixedSingle;
			//keep it like that!
		}

		#endregion

		#region "Override"

		protected override void OnMouseEnter(EventArgs e)
		{
			base.OnMouseEnter(e);
			State = State.Hot;
		}

		protected override void OnMouseLeave(EventArgs e)
		{
			base.OnMouseLeave(e);
			if ( !ContainsFocus )
			{
				State = State.Normal;
			}
		}
      
		protected override void OnGotFocus(EventArgs e)
		{
			base.OnGotFocus(e);
			State = State.Hot;
		}
        
		protected override void OnLostFocus(EventArgs e)
		{
			base.OnLostFocus(e);
			State=State.Normal;
		}

		protected override  void WndProc(ref Message m)
		{
			
			base.WndProc(ref m);	
	
			if(m.Msg==(int)Msgs.WM_PAINT)
			{
				PaintBorder(this.State);
			}			
		}
	

		#endregion

		#region"Implementation"

		private void PaintBorder(State state)
		{
			using (Graphics g=this.CreateGraphics())
			{
				Color borderColor;
				if(Enabled)
				{					
					if (State==State.Normal)
					{
						if(ReadOnly){borderColor=CustomControls.BaseClasses.AppColors.ToolbarColorLight;}
						else {borderColor=(this.Parent!=null)?Parent.BackColor:CustomControls.BaseClasses.AppColors.ControlColor;}
					}
					else{borderColor=  CustomControls.BaseClasses.AppColors.HighlightColorDarkDark;}
				}
				else{borderColor=CustomControls.BaseClasses.AppColors.ToolbarBackColor;}
				
				using (Pen pen= new Pen(borderColor))
				{
					g.DrawRectangle(pen,new Rectangle(0,0,this.Width-1, this.Height-1));
				}
				
			}
		}

		#endregion

	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Daniel Zaharia
Web Developer
Romania Romania
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 30 Jan 2004
Article Copyright 2004 by Daniel Zaharia
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid