// listBox1 has DrawMode property set to DrawMode.OwnerDrawFixed
// Event handler for listBox1.DrawItem event
private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
// Render listBox1 background
e.DrawBackground();
if((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
// If item is selected, draw a red selection box
e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
// Draw white text
e.Graphics.DrawString(this.listBox1.Items[e.Index].ToString(), this.listBox1.Font, Brushes.White, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
}
else
{
// If item is not selected, just draw text in black
e.Graphics.DrawString(this.listBox1.Items[e.Index].ToString(), this.listBox1.Font, Brushes.Black, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
}
}