Download Source Code
Here is a quick screen shot of the sample code demonstrating the selected color as being red.

Here is the source code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using EggHeadCafe.Drawing;
namespace EggHeadCafe.IconDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void cmdFontColor_Click(object sender, EventArgs e)
{
System.Drawing.Color color = GetColorFromDialog();
IconController.DrawColorBar(this.tsbFontColor.Image,color);
this.tsbFontColor.Invalidate();
}
private void cmdLineColor_Click(object sender, EventArgs e)
{
System.Drawing.Color color = GetColorFromDialog();
IconController.DrawColorBar(this.tsbLineColor.Image,color);
this.tsbLineColor.Invalidate();
}
private void cmdFillColor_Click(object sender, EventArgs e)
{
System.Drawing.Color color = GetColorFromDialog();
IconController.DrawColorBar(this.tsbFillColor.Image,color);
this.tsbFillColor.Invalidate();
}
private System.Drawing.Color GetColorFromDialog()
{
if (this.colorDialog1.ShowDialog() == DialogResult.OK)
{
return this.colorDialog1.Color;
}
return Color.Empty;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace EggHeadCafe.Drawing
{
public class IconController
{
#region Draw Color Bar
public static void DrawColorBar(Image icon,Color color,int x,int y, int width)
{
int height = 2;
try
{
if (color == Color.Empty) { return; }
Graphics g = Graphics.FromImage(icon);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle bgImg = new Rectangle(x, y, width, height);
SolidBrush bgBrush = new SolidBrush(color);
g.FillRectangle(bgBrush, bgImg);
bgBrush.Dispose();
}
catch (Exception) { throw; }
}
#endregion
#region Draw Color Bar
public static void DrawColorBar(Image icon,Color color,int x, int y)
{
try
{
DrawColorBar(icon,color,x,y,14);
}
catch (Exception) { throw; }
}
#endregion
#region Draw Color Bar
public static void DrawColorBar(Image icon,Color color)
{
try
{
DrawColorBar(icon,color,1,13);
}
catch (Exception) { throw; }
}
#endregion
}
} |