private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { if (e.Index >= 0 && e.Index < listBox1.Items.Count) { System.Drawing.Rectangle rc = e.Bounds; rc.X = e.Bounds.Left + 2; rc.Y = e.Bounds.Top + 2; Type tp = (Type)listBox1.Items[e.Index]; Image img = DrawingItem.GetTypeIcon(tp); if ((e.State & DrawItemState.Selected) != 0) { //fill background e.Graphics.FillRectangle(m_brushBKSelected, e.Bounds); //draw image e.Graphics.DrawImage(img, rc.Left, rc.Top); //write name rc.X = rc.Left + img.Width + 2; e.Graphics.DrawString(tp.Name, m_font, m_brushWhite, rc); } else { //fill name background e.Graphics.FillRectangle(m_brushWhite, e.Bounds); //draw image e.Graphics.DrawImage(img, rc.Left, rc.Top); //write name rc.X = rc.Left + img.Width + 2; e.Graphics.DrawString(tp.Name, m_font, m_brushBlack, rc); } //draw name box e.Graphics.DrawRectangle(m_penLine, e.Bounds); } }