protected override void OnDrawItem(DrawComboBoxItemEventArgs e) { if (e.IsSelected) { e.PaintSelectedBackground(); } else { e.PaintNormalBackground(); } FontFamily fontFamily = (FontFamily)Items[e.ItemIndex]; using (Font font = CreateSampleFont(fontFamily, 12)) { using (Brush b = new SolidBrush(e.TextColor)) { using (StringFormat sf = new StringFormat(StringFormat.GenericDefault)) { sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; e.Graphics.DrawString( fontFamily.Name, font, b, e.Bounds, sf); } } } }
protected override void OnDrawItem(DrawComboBoxItemEventArgs e) { if (e.IsSelected) e.PaintSelectedBackground(); else e.PaintNormalBackground(); FontFamily fontFamily = (FontFamily)Items[e.ItemIndex]; using (Font font = CreateSampleFont(fontFamily, 12)) { using (Brush b = new SolidBrush(e.TextColor)) { using (StringFormat sf = new StringFormat(StringFormat.GenericDefault)) { sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; e.Graphics.DrawString( fontFamily.Name, font, b, e.Bounds, sf); } } } }
protected override void OnDrawItem(DrawComboBoxItemEventArgs e) { BrushSample brushSample = Items[e.ItemIndex] as BrushSample; if (brushSample == null) { base.OnDrawItem(e); return; } if (e.IsSelected) { e.PaintSelectedBackground(); } else { e.PaintNormalBackground(); } Rectangle sampleBounds = new Rectangle(e.Bounds.Location, _brushSampleSize); sampleBounds.X += (e.Bounds.Width - _brushSampleSize.Width) / 2; sampleBounds.Y += (e.Bounds.Height - _brushSampleSize.Height) / 2; Rectangle boundingLineBounds = sampleBounds; boundingLineBounds.Offset(-1, -1); boundingLineBounds.Width += 1; boundingLineBounds.Height += 1; using (Pen p = new Pen(Color.Black)) { e.Graphics.DrawRectangle(p, boundingLineBounds); } e.Graphics.DrawImage(brushSample.BrushSampleImage, sampleBounds); }
protected override void OnDrawItem(DrawComboBoxItemEventArgs e) { BrushSample brushSample = Items[e.ItemIndex] as BrushSample; if (brushSample == null) { base.OnDrawItem(e); return; } if (e.IsSelected) e.PaintSelectedBackground(); else e.PaintNormalBackground(); Rectangle sampleBounds = new Rectangle(e.Bounds.Location, _brushSampleSize); sampleBounds.X += (e.Bounds.Width - _brushSampleSize.Width)/2; sampleBounds.Y += (e.Bounds.Height - _brushSampleSize.Height)/2; Rectangle boundingLineBounds = sampleBounds; boundingLineBounds.Offset(-1, -1); boundingLineBounds.Width += 1; boundingLineBounds.Height += 1; using (Pen p = new Pen(Color.Black)) { e.Graphics.DrawRectangle(p, boundingLineBounds); } e.Graphics.DrawImage(brushSample.BrushSampleImage, sampleBounds); }