C# Color of listbox item continued
<p>I'm trying to find a way to highlight the background of list box items with different colors, and came across this four year old closed thread that almost answers the question here:</p>

<p><a href="http://stackoverflow.com/questions/91747/background-color-of-a-listbox-item-winforms#91758">Background color of a ListBox item (winforms)</a></p>

<p>I'm not following how to use his method.  So if I created an object named listBox1 and a string variable named strSomeString, what would be the exact code for adding strSomeString to listBox1 with a red background?</p>

<p>Using Shadow Wizard's code here:</p>

<pre><code>    private void lbReports_DrawItem(object sender, DrawItemEventArgs e)
    {
        e.DrawBackground();

        bool selected = ((e.State &amp; DrawItemState.Selected) == DrawItemState.Selected);

        int index = e.Index;
        if (index &gt;= 0 &amp;&amp; index &lt; lbReports.Items.Count)
        {
            string text = lbReports.Items[index].ToString();
            Graphics g = e.Graphics;

            Color color = (selected) ? Color.FromKnownColor(KnownColor.Highlight) : (((index % 2) == 0) ? Color.White : Color.Gray);
            g.FillRectangle(new SolidBrush(color), e.Bounds);

            // Print text
            g.DrawString(text, e.Font, (selected) ? reportsForegroundBrushSelected : reportsForegroundBrush, 
                lbReports.GetItemRectangle(index).Location);
        }

        e.DrawFocusRectangle();
    }
</code></pre>

<p>-Thanks</p>
