Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about the Color Structure... 4

pzmgmb

Programmer
Apr 2, 2003
115
0
0
US
Does Microsoft have a poster or something that displays all the colors available in the color structure? It would be a nice reference to have so i know what "Antique White" or "Blanched Almond" looked like.
 
I still have no idea WTH they were thinking with that. I mean, who's going to search a list of colors alphabeticly?

Customer: Sorry dev, that color is just a tad to blue, do you have anything closer to slate?
Dev: I can try SlateGrey, or maybe puce if you like?
Customer: Puce, is that a color?
Dev: Acording to Microsoft no, but the Church Lady from SNL said it was.

-Rick

----------------------
http://www.ringdev.com

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
I completely agree.

I don't know of a poster, but you could always code your own poster to display coloured boxes with GDI+ and print it out. There's also a website:
http://www.hello-world.com/vbn/resource/colors.php
which is set up such that if you mouseover one of the colours in the list it sets the background colour to that.
 
maybe if I get modivated and have the time I'll write an app to display them in order of hue/lum. That'd be nicer then looking at the alphabetical layout on that site.

-Rick

----------------------
http://www.ringdev.com

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
I wrote something similar to the web page. In my app you can drag the color rects and you can see the RGB and ole values of them. The text color is white or black according to the brightness of the back color.

This is not a well written code but you can modify it. For example, using reflection to create the color names string array is better.

It is written in c#.

Code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ColorPicker
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label1;
		private bool IsMouseDown = false;
		private int OldX;
		private int OldY;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			InitializeComponent();

			string[] colors = new string[]{"AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue",
											  "BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk",
											  "Crimson","Cyan","DarkBlue","DarkCyan","DarkGoldenrod","DarkGray","DarkGreen","DarkKhaki","DarkMagenta",
											  "DarkOliveGreen","DarkOrange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray",
											  "DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray","DodgerBlue","Firebrick","FloralWhite",
											  "ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","Goldenrod","Gray","Green","GreenYellow","Honeydew",
											  "HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen","LemonChiffon",
											  "LightBlue","LightCoral","LightCyan","LightGoldenrodYellow","LightGray","LightGreen","LightPink","LightSalmon",
											  "LightSeaGreen","LightSkyBlue","LightSlateGray","LightSteelBlue","LightYellow","Lime","LimeGreen","Linen",
											  "Magenta","Maroon","MediumAquamarine","MediumBlue","MediumOrchid","MediumPurple","MediumSeaGreen",
											  "MediumSlateBlue","MediumSpringGreen","MediumTurquoise","MediumVioletRed","MidnightBlue","MintCream","MistyRose",
											  "Moccasin","Navy","OldLace","Olive","OliveDrab","Orange","OrangeRed","Orchid","PaleGoldenrod","PaleGreen",
											  "PaleTurquoise","PaleVioletRed","PapayaWhip","PeachPuff","Peru","Pink","Plum","PowderBlue","Purple",
											  "Red","RosyBrown","RoyalBlue","SaddleBrown","Salmon","SandyBrown","SeaGreen","SeaShell","Sienna","Silver",
											  "SkyBlue","SlateBlue","SlateGray","Snow","SpringGreen","SteelBlue","Tan","Teal","Thistle","Tomato", 
											  "Turquoise","Violet","Wheat","White","WhiteSmoke","Yellow","YellowGreen","Transparent"};

			Label[] labels = new Label[colors.Length];
			int row = 0;
			int column = 0;
			int ColorLuminance;

			for (int i=0; i<labels.Length; i++)
			{
				labels[i] = new Label();
				labels[i].BorderStyle = label1.BorderStyle;
				labels[i].TextAlign = label1.TextAlign;
				labels[i].Font = label1.Font;
				labels[i].Size = label1.Size;
				labels[i].Top = row * label1.Height;
				labels[i].Left = column * label1.Width;
				labels[i].BackColor = Color.FromName(colors[i]);
				ColorLuminance = labels[i].BackColor.R * 2 + labels[i].BackColor.G * 5 + labels[i].BackColor.B;
				if (ColorLuminance < 1024)
					labels[i].ForeColor = Color.White;
				else
					labels[i].ForeColor = Color.Black;

				labels[i].MouseDown += new MouseEventHandler(eMouseDown);
				labels[i].MouseUp += new MouseEventHandler(eMouseUp);
				labels[i].MouseMove += new MouseEventHandler(eMouseMove);

				if (colors[i].IndexOf("Gray") > -1)
					labels[i].ForeColor = Color.Black;

				labels[i].Text = colors[i] + " R" + labels[i].BackColor.R.ToString() + " G" + labels[i].BackColor.G.ToString()+ 
						" B" + labels[i].BackColor.B.ToString() + " OLE " + ColorTranslator.ToOle(labels[i].BackColor).ToString();

				if (column == 7)
				{
					row++;
					column = 0;
				}
				else
					column++;
			}

			Controls.AddRange(labels);
		}
		/// <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 Windows Form 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()
		{
			this.panel1 = new System.Windows.Forms.Panel();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panel1.Location = new System.Drawing.Point(88, 56);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(112, 40);
			this.panel1.TabIndex = 0;
			this.panel1.Visible = false;
			// 
			// label1
			// 
			this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 7F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(177)));
			this.label1.Location = new System.Drawing.Point(0, 0);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(120, 35);
			this.label1.TabIndex = 1;
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			this.label1.Visible = false;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.AutoScroll = true;
			this.ClientSize = new System.Drawing.Size(930, 142);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.panel1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "Form1";
			this.Text = "Colors";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void eMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			IsMouseDown = true;
			Cursor = Cursors.Hand;
			OldX = MousePosition.X;
			OldY = MousePosition.Y;
		}

		private void eMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			IsMouseDown = false;
			Cursor = Cursors.Default;
		}

		private void eMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (IsMouseDown)
			{
				Label tmpLbl = (Label)sender;
				tmpLbl.BringToFront();
				tmpLbl.Location = new Point(tmpLbl.Location.X + MousePosition.X - OldX, tmpLbl.Location.Y + MousePosition.Y - OldY);
				OldX = MousePosition.X;
				OldY = MousePosition.Y;

			}
		}

	}
}
 
So over the last few days in my spare time, I have become motivated enough to make a program to do this (read: avoiding documentation).

Preview image:
ColorChart.jpg


Source code: (built in VS.Net 2k2)
http://ringdev.com/code/ColorChart.zip

I should warn you though, the source code is pretty ugly. There is no documentation in it, it's poorly organized, and all round pretty cruddy. But it works, and I'm not making a thesis paper out of it. Enjoy!

-Rick

----------------------
http://www.ringdev.com

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
I threw a new copy up on the web site, cleaned it up abit, turned on option strict, put in some comments. Enjoy, hope it helps people. I learned a thing or two while making it.

-Rick

----------------------
http://www.ringdev.com

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Is that the best you can do?

I'll give you a star, not that you've earned it!

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Compared to some of the other projects I've worked on in the last few monthes, this one was a nice little break. I always liked looking at colors ;)

I did notice that link that RG posted in the 'blur line' thread. Made me think about adding some neat effects to this thing.

Only 2600 more items to document...

-Rick

----------------------
http://www.ringdev.com

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
ThatRickGuy,

What did you mean about this? I'm sorry I dont get it.

I did notice that link that RG posted in the 'blur line' thread. Made me think about adding some neat effects to this thing
 
In this thread: http://www.tek-tips.com/viewthread.cfm?qid=1027623&page=1 RiverGuy (RG) posted a link to a great GDI+ site.

-Rick

----------------------
http://www.ringdev.com

[monkey] I believe in killer coding ninja monkeys.[monkey]
 

Part and Inventory Search

Sponsor

Back
Top