首先还是感谢https://stackoverflow.com/questions/4667532/colour-individual-items-in-a-winforms-combobox
这个国外的帖子给的帮助,我已经将他翻译过来了,
首先你需要在combobox的属性页里面设置
DrawMode为OwnerDrawFixed / OwnerDrawVariable以触发combobox 的DrawItem事件,这个时候我们重写这个事件,来重绘下拉框里面的颜色。
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
// Draw the background
e.DrawBackground();
// Get the item text
string text = ((ComboBox)sender).Items[e.Index].ToString();
// Determine the forecolor based on whether or not the item is selected
Brush brush;
brush = Brushes.Black;
// Draw the text
e.Graphics.DrawString(text, ((Control)sender).Font, brush, e.Bounds.X, e.Bounds.Y);
}
记得绑定。
完事,收工。