private ColorRec GetColorRec( int index) { if (index < 0 || index >= Items.Count) { return(ColorRec.Empty); } if (Items[index] is ColorRec) { return((ColorRec)Items[index]); } return(ColorRec.Parse(Items[index] as string)); }
protected override void OnDrawItem( DrawItemEventArgs e) { e.DrawBackground(); ColorRec cr = GetColorRec(e.Index); var markRect = new Rectangle { X = e.Bounds.Left + c_ColorMarkLeftPadding, Y = e.Bounds.Top + c_ColorMarkTopBottomPaddings, Height = e.Bounds.Height - c_ColorMarkTopBottomPaddings - c_ColorMarkTopBottomPaddings }; markRect.Width = markRect.Height; var textRect = new Rectangle { X = e.Bounds.Left + markRect.Right + c_ColorMarkRightPadding, Y = e.Bounds.Top }; textRect.Width = e.Bounds.Width - textRect.X - 2; textRect.Height = e.Bounds.Height; Utils.DrawColorMark(e.Graphics, cr.Value, true, markRect); TextRenderer.DrawText( e.Graphics, cr.GetDisplayText(), Font, textRect, ((e.State & DrawItemState.Selected) != 0) ? SystemColors.HighlightText : ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); if ((e.State & DrawItemState.Focus) != 0) { ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds); } base.OnDrawItem(e); }