这是我在listBox1_DrawItem的事件里的,如下是错误与代码,我试过用if (listBox1.SelectedItem != null),但是他不会正常加载item了,所以不太行
StringFormat strFmt = new StringFormat
{
Alignment = StringAlignment.Center, //文本垂直居中
LineAlignment = StringAlignment.Center //文本水平居中
};
e.DrawBackground();
Graphics g = e.Graphics;
Brush brush = ((e.State & DrawItemState.Selected) == DrawItemState.Selected) ?
new SolidBrush(Color.FromArgb(224, 231, 255)) : new SolidBrush(e.BackColor);
g.FillRectangle(brush, e.Bounds);
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font,
new SolidBrush(e.ForeColor), e.Bounds, strFmt);
e.DrawFocusRectangle();