The form does not have an OnDrawItem event, so there is nothing to override.
Instead, you need to use the DrawItem event in the combo box:
public frmDlgGraphOptions() { InitializeComponent(); CmbBoxlineStyles.DropDownStyle = ComboBoxStyle.DropDownList; CmbBoxlineStyles.DrawMode = DrawMode.OwnerDrawFixed; CmbBoxlineStyles.DrawItem += CmbBoxlineStyles_DrawItem; } void CmbBoxlineStyles_DrawItem(object sender, DrawItemEventArgs e) {
Make sure you set the DrawMode property so that the control can call your draw method.
If you are trying to create your own ComboBox control that draws these positions, I suspect this might be what you are looking for:
public class MyCombo : ComboBox { public MyCombo() { this.DropDownStyle = ComboBoxStyle.DropDownList; this.DrawMode = DrawMode.OwnerDrawFixed; } protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Index > -1) { int startX = e.Bounds.Left + 5; int startY = (e.Bounds.Y + e.Bounds.Height / 2); int endX = e.Bounds.Right - 5; int endY = (e.Bounds.Y + e.Bounds.Height / 2); using (Pen p = new Pen(Color.Blue, (Int32)this.Items[e.Index])) { e.Graphics.DrawLine(p, new Point(startX, startY), new Point(endX, endY)); } } base.OnDrawItem(e); } }
Then you simply add your pen size numbers when using the control:
MyCombo CmbBoxlineStyles = new MyCombo(); CmbBoxlineStyles.Items.Add(1); CmbBoxlineStyles.Items.Add(2); CmbBoxlineStyles.Items.Add(3); CmbBoxlineStyles.Items.Add(4);
Result:

Larstech
source share