110,537
社区成员
发帖
与我相关
我的任务
分享
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index != -1)
{
Graphics g = e.Graphics;
Rectangle r = e.Bounds;
Size imageSize = imglist.ImageSize;
Font fn = null;
if (e.Index >= 0)
{
fn = new Font("Ariel ", 12, FontStyle.Bold);
string s = (string)cmbbox.Items[e.Index];
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
//画条目背景
e.Graphics.FillRectangle(new SolidBrush(Color.Red), r);
//绘制图像
imglist.Draw(g, r.Left, r.Top, e.Index);
//显示字符串
e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black), r.Left + imageSize.Width, r.Top);
//显示取得焦点时的虚线框 //
e.DrawFocusRectangle();
}
else
{
e.Graphics.FillRectangle(new SolidBrush(Color.White), r);
imglist.Draw(e.Graphics, r.Left, r.Top, e.Index);
e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black), r.Left + imageSize.Width, r.Top);
e.DrawFocusRectangle();
}
}
}
}