private void lbStyle_DrawItem(object sender, DrawItemEventArgs e) { const int PadX = 4; const int Gap = 8; // gap between text and line Doc.DashStyle item = (Doc.DashStyle)lbStyle.Items[e.Index]; if (item == Doc.DashStyle.None) { using (SolidBrush brush = new SolidBrush(e.ForeColor)) { e.DrawBackground(); e.Graphics.DrawString("(None)", this.Font, brush, e.Bounds); } } else { using (Pen pen = new Pen(e.ForeColor, (50 / 1440f) * e.Graphics.DpiY)) using (SolidBrush brush = new SolidBrush(e.BackColor)) { pen.DashStyle = ToDashStyle(item); e.Graphics.FillRectangle(brush, e.Bounds); e.Graphics.DrawLine(pen, e.Bounds.Left + Gap / 2, e.Bounds.Top + e.Bounds.Height / 2, e.Bounds.Right - PadX, e.Bounds.Top + e.Bounds.Height / 2); } } e.DrawFocusRectangle(); }
private DashStyle ToDashStyle(Doc.DashStyle style) { switch (style) { case Doc.DashStyle.Solid: return(DashStyle.Solid); case Doc.DashStyle.Dash: return(DashStyle.Dash); case Doc.DashStyle.Dot: return(DashStyle.Dot); case Doc.DashStyle.DashDot: return(DashStyle.DashDot); case Doc.DashStyle.DashDotDot: return(DashStyle.DashDotDot); default: System.Diagnostics.Debug.Assert(false); return(DashStyle.Custom); } }