protected override void OnDrawItem(DrawItemEventArgs e) { DrawItemEventHandler handler = GetDrawItemHandler(); if (handler == null) { Graphics g = e.Graphics; Rectangle itemRect = e.Bounds; if ((e.State & DrawItemState.Selected) > 0) { itemRect.Width--; } DrawItemState state = e.State; int imageIndex = UseFirstImage ? 0 : e.Index; string text = Text; if (e.Index != -1) { text = this.GetItemText(Items[e.Index]); } StiControlPaint.DrawItem(g, itemRect, state, text, ImageList, imageIndex, Font, BackColor, ForeColor, RightToLeft); } else { handler(this, e); } }
protected override void OnDrawItem(DrawItemEventArgs e) { if ((e.Index != -1 || drawCombo) && Enabled) { string fontName = SelectedFont.Name; if (e.Index != -1) { fontName = Items[e.Index].ToString(); } Rectangle itemRect = e.Bounds; if ((e.State & DrawItemState.Selected) > 0) { itemRect.Width--; } StiControlPaint.DrawItem(e.Graphics, itemRect, e.State, fontName, null, e.Index, Font, BackColor, ForeColor, 30, base.RightToLeft); var rect = new Rectangle(e.Bounds.X, e.Bounds.Y, 28, e.Bounds.Height - 1); var g = e.Graphics; if (((e.State & DrawItemState.Focus) > 0) || ((e.State & DrawItemState.Selected) > 0)) { g.DrawRectangle(StiPens.SelectedText, rect); } if (Enabled) { #region Sample draw using (var sf = new StringFormat()) { sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; if (this.RightToLeft == RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } using (var fnt = new Font(fontName, 10)) { g.DrawString("ab", fnt, StiBrushes.SelectedText, rect, sf); } } #endregion } } }
private void DrawItem(bool web, object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index != -1) { Color color = Color.Empty; string colorName = null; if (web) { color = StiColors.Colors[e.Index]; colorName = StiLocalization.Get("PropertyColor", color.Name); } else { color = StiColors.SystemColors[e.Index]; colorName = StiLocalization.Get("PropertySystemColors", color.Name); } var g = e.Graphics; var rect = e.Bounds; if ((e.State & DrawItemState.Selected) > 0) { rect.Width--; } var colorRect = new Rectangle(rect.X + 2, rect.Y + 2, 22, rect.Height - 5); var textRect = new Rectangle(colorRect.Right + 2, rect.Y, rect.Width - colorRect.X, rect.Height); StiControlPaint.DrawItem(g, rect, e.State, SystemColors.Window, SystemColors.ControlText); using (var brush = new SolidBrush(color)) { g.FillRectangle(brush, colorRect); } g.DrawRectangle(Pens.Black, colorRect); using (var sf = new StringFormat()) { if (this.RightToLeft == RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } g.DrawString(colorName, Font, Brushes.Black, textRect, sf); } } }