Click here to Skip to main content
15,896,359 members
Articles / Multimedia / GDI+

Report Builder

Rate me:
Please Sign up or sign in to vote.
4.75/5 (36 votes)
10 Jun 2004CPOL16 min read 255.8K   6.9K   157  
Article on a simple report builder.
using System;
using STI_Library.BaseClasses;
using STI_Library.HelperClasses;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;

namespace STI_Library.Win32Controls
{
	
	public class STI_DropDownColorPicker:STI_DropDownListBox
	{

		private Color _Value=Color.White;
		public event EventHandler ValueChanged;
		private ColorListBox CList= new ColorListBox();


		public override ListBox List
		{
			get{return CList;}
		}

		public Color Value
		{
			get{return _Value;}
			set
			{
				if(value !=_Value)
				{
					_Value= value;
					Text=value.Name;
					OnValueChanged(new EventArgs());
					Invalidate(); 
				}
			}
		}


		public STI_DropDownColorPicker()
		{
			this.DropDownStyle=ComboBoxStyle.DropDownList;
			this.List.SelectedIndexChanged+=new EventHandler(List_SelectedIndexChanged);
		}


		protected virtual void OnValueChanged(System.EventArgs e)
		{			
			if(ValueChanged!= null)	{ValueChanged(this,e);}
		}

		protected override void DrawText(System.Drawing.Graphics g, string text, System.Drawing.Font font, System.Drawing.Rectangle bounds, System.Drawing.StringFormat strformat)
		{
			using ( SolidBrush colBrush= new SolidBrush(Value))
			{			
				
				Rectangle colRect=GetColorRect(bounds);
				
				g.FillRectangle(colBrush,colRect);
				g.DrawRectangle( Enabled? Pens.Black:Pens.DarkGray,colRect);
				
				base.DrawText(g,text,font,GetTextRect(colRect, bounds),strformat);
				
			}
		}
		
		private Rectangle GetColorRect(Rectangle bounds)
		{
			return new Rectangle(bounds.X + 2, Math.Max(0,Math.Min(3,bounds.Height-3)),Math.Min(bounds.Width-5,22) ,Math.Max(0,bounds.Height-5));
		}
		
		private Rectangle GetTextRect(Rectangle ColRect,Rectangle bounds)
		{
			return new Rectangle(ColRect.Width+3,ColRect.Top,bounds.Width-ColRect.Width-3, ColRect.Height);
		}
		

		private void List_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.Value=Color.FromName(List.SelectedItem.ToString());
		}
		

	}
}

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)


Written By
Web Developer
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions