protected override void OnDrawItem(DrawItemEventArgs e) { Graphics grfx = e.Graphics; Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height); rectColor.Inflate(-1, -1); Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height, e.Bounds.Top, e.Bounds.Width - 2 * e.Bounds.Height, e.Bounds.Height); if (this.Enabled) { e.DrawBackground(); } grfx.DrawRectangle(new Pen(e.ForeColor), rectColor); string text = string.Empty; object objAtIndex = e.Index >= 0 ? Items[e.Index] : SelectedItem; if (objAtIndex is Color) { Color itemColor = (Color)objAtIndex; grfx.FillRectangle(new SolidBrush(itemColor), rectColor); if (itemColor.IsNamedColor) { text = itemColor.Name; } else if (ColorDictionary.IsBaseColorNamed(itemColor)) { int transparency = ((255 - itemColor.A) * 100) / 255; text = "T" + transparency.ToString() + ColorDictionary.GetBaseColorName(itemColor); } else { text = "Custom Color"; } } else if (objAtIndex is BrushX) { BrushX itemBrush = (BrushX)objAtIndex; itemBrush.Rectangle = rectColor; grfx.FillRectangle(itemBrush, rectColor); text = "Custom Brush"; } grfx.DrawString(text, Font, new SolidBrush(e.ForeColor), rectText); }
protected override void OnDrawItem(DrawItemEventArgs e) { Graphics grfx = e.Graphics; Rectangle rectColor = new Rectangle(e.Bounds.Left, e.Bounds.Top, 2 * e.Bounds.Height, e.Bounds.Height); rectColor.Inflate(-1, -1); Rectangle rectText = new Rectangle(e.Bounds.Left + 2 * e.Bounds.Height, e.Bounds.Top, e.Bounds.Width - 2 * e.Bounds.Height, e.Bounds.Height); if (this.Enabled) { e.DrawBackground(); } grfx.DrawRectangle(new Pen(e.ForeColor), rectColor); Color itemColor = e.Index < 0 ? Color.Black : (Color)Items[e.Index]; grfx.FillRectangle(new SolidBrush(itemColor), rectColor); string text = "Custom"; if (itemColor.IsNamedColor) { text = itemColor.Name; } else if (ColorDictionary.IsBaseColorNamed(itemColor)) { int transparency = ((255 - itemColor.A) * 100) / 255; text = "T" + transparency.ToString() + ColorDictionary.GetBaseColorName(itemColor); } grfx.DrawString(text, Font, new SolidBrush(e.ForeColor), rectText); }