日期:2014-05-17 浏览次数:20806 次
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
listBox1.DrawMode = DrawMode.OwnerDrawFixed; //允许手动设置控件元素
// 定义默认笔刷的颜色
Brush myBrush = Brushes.Black;
//设置奇偶不同的笔刷
if (e.Index % 2 == 0)
{
myBrush = Brushes.Red;
}
else
{
myBrush = Brushes.Blue;
}
// 根据设置的笔刷重新绘制项
e.DrawBackground();
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, myBrush,
e.Bounds, StringFormat.GenericDefault);
// e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, myBrush,
// e.Bounds, StringFormat.GenericDefault);
// 绘制聚焦框
e.DrawFocusRectangle();
}