C#使用listbox左侧显示图片右侧显示文字,就像qq多人聊天一样的效果,
我将listbox重绘 private Color RowBackColorAlt = Color.FromArgb(185, 210, 234);//交替色
private Color RowBackColorSel = Color.FromArgb(106, 197, 242);//选中项目颜色
private void lbNN_DrawItem(object sender, DrawItemEventArgs e)
{
Brush myBrush = Brushes.Black;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
myBrush = new SolidBrush(RowBackColorSel);
}
else if (e.Index % 2 == 0)
{
myBrush = new SolidBrush(RowBackColorAlt);
}
else
{
myBrush = new SolidBrush(Color.White);
}
e.Graphics.FillRectangle(myBrush, e.Bounds);
e.DrawFocusRectangle();//焦点框
//绘制图表
Image image = Image.FromFile(@"..\..\ico\聊天界面头像2.png");
Graphics g = e.Graphics;
Rectangle bounds = e.Bounds;
Rectangle imageRect = new Rectangle(bounds.X, bounds.Y, bounds.Height, bounds.Width);
Rectangle textRect = new Rectangle(imageRect.Right, bounds.X,
bounds.Width - imageRect.Right, bounds.Height);
if (image != null)
{
g.DrawImage(image, imageRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
}
//文本
StringFormat strFormat = new StringFormat();
strFormat.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString(lbNN.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), textRect, strFormat);
}以上是我的代码,可是我不知道怎么在窗体的load事件里写了,运行时没有反应,只有单击listbox的时候闪一下,请问大神怎么写才能实现,初来乍到还不懂什么,请问如何在窗体加载的时候就可以显示listbox的头像和昵称呢,