C# 我目前有一个win表单,我可以在列表框中显示两个列表,但是由于这两个列表已合并,因此数据可能有点令人困惑。无论如何,我可以将List 1的项目颜色设置为蓝色,将List 2的项目颜色设置为红色吗?
private void updatesum()
{
listBox.Items.Clear();
List<String> listOfDels = theDatabase.listDeliveries();
List<String> listofPicks = theDatabase.listPickups();
listBox.Items.AddRange(listOfDels.ToArray());
listBox.Items.AddRange(listofPicks.ToArray());
}
答案 0 :(得分:2)
您必须订阅ListBox的DrawItem并自己绘制BackColor:
listBox.DrawItem += new DrawItemEventHandler(listBox_DrawItem);
我认为您的活动应该是这样的:
private void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(Color.Blue), e.Bounds);
g.DrawString(listBox.Items[e.Index].ToString(),
e.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
答案 1 :(得分:0)