1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
| private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) { if ((e.State & ListViewItemStates.Selected) != 0) { Rectangle OuterRect = new Rectangle(e.Bounds.Left + 1, e.Bounds.Top + 1, e.Bounds.Width - 2, e.Bounds.Height - 2); e.Graphics.FillRectangle(Brushes.AliceBlue, e.Bounds); Pen OuterRectPen = new Pen(Color.Aqua, 2); e.Graphics.DrawRectangle(OuterRectPen, OuterRect); } else { e.Graphics.FillRectangle(Brushes.White, e.Bounds); } }
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { TextFormatFlags flags = TextFormatFlags.Left;
using (StringFormat sf = new StringFormat()) { switch (e.Header.TextAlign) { case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; flags = TextFormatFlags.HorizontalCenter; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; flags = TextFormatFlags.Right; break; }
double subItemValue; if (e.ColumnIndex > 0 && Double.TryParse( e.SubItem.Text, NumberStyles.Currency, NumberFormatInfo.CurrentInfo, out subItemValue) && subItemValue < 0) { if ((e.ItemState & ListViewItemStates.Selected) == 0) { e.DrawBackground(); }
e.Graphics.DrawString(e.SubItem.Text, listView1.Font, Brushes.Red, e.Bounds, sf);
return; }
e.DrawText(flags); } }
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { using (StringFormat sf = new StringFormat()) { switch (e.Header.TextAlign) { case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; break; }
e.DrawBackground();
using (Font headerFont = new Font("Helvetica", 8, FontStyle.Regular)) { e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Black, e.Bounds, sf); } } return; } |