在combobox中画出图片了,但显示图片的大小怎么就是无法改变,改combobox的大小也没用,只不是只有改e.Graphic啊,要如何改啊
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();
}
}
}
}
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();
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货