> If you post a question and then solve it yourself, it is polite and
> customary to post your solution.
[quoted text clipped - 4 lines]
>
> Pete
I am trully sorry for that peter and of course you are right. I apologize
for my rudeness.
namespace SettingsTest.Controls
{
class ColorComboBox : ComboBox
{
public ColorComboBox(): base()
{
this.DropDownStyle = ComboBoxStyle.DropDownList;
this.DrawMode = DrawMode.OwnerDrawFixed;
this.PopulateWithColors();
this.DrawItem += new
DrawItemEventHandler(ColorComboBox_DrawItem);
}
private void PopulateWithColors()
{
this.Items.Clear();
Color colorTable = new Color();
Type t = typeof(Color);
System.Reflection.PropertyInfo[] PropInfos = t.GetProperties();
foreach (System.Reflection.PropertyInfo PropInfo in PropInfos)
{
if (PropInfo.PropertyType == typeof(Color))
{
Color color = (Color)PropInfo.GetValue(colorTable,
null);
this.Items.Add(color.Name);
}
}
}
void ColorComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
string ColorName = string.Empty;
if (e.Index >= 0)
{
ColorName = (string)((ComboBox)sender).Items[e.Index];
}
// Get the Bounding rectangle for a selected item
Rectangle SelRect = new Rectangle(e.Bounds.X, e.Bounds.Y,
e.Bounds.Width, e.Bounds.Height);
// Get the Bounding rectangle for the color rectangle in front
of the items
Rectangle ColorRect = new Rectangle(5, e.Bounds.Top + 2, 11,
e.Bounds.Height - 4);
using (Brush TextBrush = new SolidBrush(e.BackColor))
{
using (Brush RectBrush = new
SolidBrush(Color.FromName(ColorName)))
{
// Paint the item
e.Graphics.FillRectangle(TextBrush, SelRect);
// Paint the litle rectangle in front of the colorname
e.Graphics.FillRectangle(RectBrush, ColorRect);
e.DrawFocusRectangle();
}
}
using (Brush brush = new SolidBrush(e.ForeColor))
{
e.Graphics.DrawString(ColorName, e.Font, brush, 20,
e.Bounds.Top);
}
}
}
}
Thank you for giving me the right direction :)
Regards,
Bart