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

WinForm Style Sheet

, 22 Jun 2004
An article on setting styles for Windows applications.
winformstylesheet_src.zip
WinformCSS
MyWinApp
App.ico
bin
Debug
obj
Debug
temp
TempPE
WinCSS
bin
Debug
obj
Debug
temp
TempPE
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Configuration;

namespace WinCSS
{
	/// <summary>
	/// Summary description for UserControl1.
	/// </summary>
	public class ErrorLabel : System.Windows.Forms.Label
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ErrorLabel()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitComponent 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 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()
		{
			// 
			// ErrorLabel
			// 
			this.AutoSize = true;
			this.Font = new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.ForeColor = System.Drawing.Color.Black;
			this.Size = new System.Drawing.Size(0, 19);

		}
		#endregion


		public override Font Font
		{
			get
			{
			//return new System.Drawing.Font("Verdana", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
				return getFont();
			}
		}

		public override Color ForeColor
		{
			get
			{
				//return System.Drawing.Color.Red;
				return getForeColor();
			}
		}

	

		public  Font getFont()
		{
			string N = ConfigurationSettings.AppSettings["ErrorLabelFontName"];
			string S = ConfigurationSettings.AppSettings["ErrorLabelFontSize"];
			string FS = ConfigurationSettings.AppSettings["ErrorLabelFontStyle"];
			string GU = ConfigurationSettings.AppSettings["ErrorLabelFontGraphicUnit"];
			string GRI = ConfigurationSettings.AppSettings["ErrorLabelFontGRI"];

			 N	= (N==null)?"Verdana":N;
			 S	= (S==null)?"10":S;
			 FS	= (FS==null)?"Bold":FS;
			 GU	= (GU==null)?"Point":GU;
			 GRI	= (GRI==null)?"0":GRI;
			
			return new System.Drawing.Font(N,(float)(Convert.ToDouble(S)),Helper.getFontStyle(FS),Helper.getGraphicUnit(GU),Convert.ToByte(GRI));
		}

		public  Color getForeColor()
		{
			string r = ConfigurationSettings.AppSettings["ErrorLabelForeColorR"];
			string g = ConfigurationSettings.AppSettings["ErrorLabelForeColorG"];
			string b = ConfigurationSettings.AppSettings["ErrorLabelForeColorB"];

			r = (r==null)?"255":r;
			g = (g==null)?"0":g;
			b = (b==null)?"0":b;

			return System.Drawing.Color.FromArgb(Convert.ToByte(r),Convert.ToByte(g),Convert.ToByte(b));
		}

	}
}

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

Ali Zolghadri
Architect
Canada Canada
I worked for the software industry as a software architect, system analyst, senior software engineer and MIS (management information system) consultant for last 10 years.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 23 Jun 2004
Article Copyright 2004 by Ali Zolghadri
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid