110,533
社区成员
发帖
与我相关
我的任务
分享
string txt = comboBox1.Items[e.Index].ToString();
e.DrawBackground();
e.DrawFocusRectangle();
if (e.State == DrawItemState.Selected)
e.Graphics.DrawString(txt, e.Font, new SolidBrush(e.ForeColor), e.Bounds);
else
e.Graphics.DrawString(txt, e.Font, new SolidBrush(e.ForeColor), e.Bounds);
this.comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
this.comboBox1.DrawItem += new DrawItemEventHandler(comboBox1_DrawItem);
}
void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string txt = this.comboBox1.Items[e.Index].ToString();
Graphics g = e.Graphics;
Font f = new Font("宋体", 9);
if (e.State == DrawItemState.Selected)
{
this.label2.Text = txt;
g.FillRectangle(Brushes.Blue, 0, e.Index * 15, this.comboBox1.Width, 12);
g.DrawString(txt, f, Brushes.White, 0, e.Index * 15);
}
else
{
g.FillRectangle(Brushes.White, 0, e.Index * 15, this.comboBox1.Width, 12);
g.DrawString(txt, f, Brushes.Black, 0, e.Index * 15);
}
}