I'm using this code to colour individual items in a listbox, but the problem i am having is it colours all previous items with the new colour. How can i colour each induvidual item without this happening?
Here is the code I'm using: (_colour is a global int)
private void debugconsole_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
e.DrawBackground();
Brush myBrush = Brushes.Black;
switch (_colour)
{
case 0:
myBrush = Brushes.Green;
break;
case 1:
myBrush = Brushes.Orange;
break;
case 2:
myBrush = Brushes.Red;
break;
case 3:
myBrush = Brushes.Gray;
break;
}
e.Graphics.DrawString(((ListBox) sender).Items[e.Index].ToString(),
e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
catch
{
MessageBox.Show("Error");
}
}