private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e)
{
if (G_ImageList != null)//判断ImageList是否为空
{
Graphics g = e.Graphics;//得到绘图对象
Rectangle r = e.Bounds;//得到绘图范围
Size imageSize = G_ImageList.ImageSize;//获取图像大小
if (e.Index >= 0)//判断是否有绘制项
{
Font fn = new Font("宋体", 10, FontStyle.Bold);//创建字体对象
string s = cbox_DisplayPictures.Items[e.Index].ToString();//得到绘制项的字符串
DrawItemState dis = e.State;
if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r);//画条目背景
G_ImageList.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();//显示取得焦点时的虚线框
}
else
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r);//画条目背景
G_ImageList.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();//显示取得焦点时的虚线框
}
}
}
}