首先设置
this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
private void comboBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
int fontSize = 8;
if (e.Index % 2 == 0)
fontSize = 8;
else
fontSize = 12;
Font fnt = new Font("Arial", fontSize, FontStyle.Bold);
SizeF siText = e.Graphics.MeasureString(comboBox1.Items[e.Index].ToString(), fnt);
e.ItemHeight = (int)siText.Height;
e.ItemWidth = (int)siText.Width;
}
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
int fontSize = 8;
Brush brush;
Graphics g = e.Graphics;
if (e.Index % 2 == 0)
{
fontSize = 8;
brush = Brushes.Black;
}
else
{
fontSize = 12;
brush = Brushes.Red;
}
Font fnt = new Font("Arial", fontSize, FontStyle.Bold);
g.DrawString(comboBox1.Items[e.Index].ToString(), fnt, brush, e.Bounds.X, e.Bounds.Y);
}