WinForm中ListBox的使用
- 获取选中数据:listbox.SelectedItem as XXX
- 重绘每一行item
- DrawMode设置为DrawMode.OwnerDrawVariable
- 然后实现DrawItem(object sender, DrawItemEventArgs e)
- 重绘选中行(鼠标所在行),如修改选中行的背景色
-
1 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) 2 { 3 e = new DrawItemEventArgs(e.Graphics, 4 e.Font, 5 e.Bounds, 6 e.Index, 7 e.State ^ DrawItemState.Selected, 8 e.ForeColor, 9 DataSourceUIParams.TableRowBackColorWhenHover); 10 } 11 12 e.DrawBackground();
-
- 重绘所有行