private void listBoxTablets_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); Graphics g = e.Graphics; int index = e.Index; if (index >= 0) { bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected); TabletInfo tableinfo = listBoxTablets.Items[index] as TabletInfo; if (selected) { g.FillRectangle(new SolidBrush(Color.FromKnownColor(KnownColor.Highlight)), e.Bounds); } else { if (tableinfo.AllDisabled()) { g.FillRectangle(new SolidBrush(Color.Gray), e.Bounds); } else if (tableinfo.PartDisabled()) { g.FillRectangle(new SolidBrush(Color.Silver), e.Bounds); } else { g.FillRectangle(new SolidBrush(Color.White), e.Bounds); } } g.DrawString(tableinfo.TableName, listBoxTablets.Font, new SolidBrush(Color.Black), e.Bounds); e.DrawFocusRectangle(); } }