WinForm中ListView設定選中行背景顏色,字型格式
{
listView1.FullRowSelect = true;
{
listView1.SelectedItems[0].SubItems[0].ForeColor = Color.Blue;
//先清除原有格式
foreach (ListViewItem item in listView1.Items)
{
item.ForeColor = Color.Black;
foreach (ListViewItem item in listView1.Items)
{
Font f = new Font(Control.DefaultFont, FontStyle.Regular);
item.Font = f;
}
//加粗字型
Font f2 = new Font(Control.DefaultFont, FontStyle.Bold);
listView1.SelectedItems[0].SubItems[0].Font = f2;
//設定選中行背景顏色
listView1.SelectedItems[0].BackColor = Color.LightBlue;
listView1.SelectedItems[0].Selected = false;
}
}
下面是設定滑鼠滑過背景變色的程式碼,這個是參考的別人的
private void listView1_MouseMove(object sender, MouseEventArgs e)
{
ListView _ListView = (ListView)sender;
ListViewItem _OldItem = null;
if (_ListView.Tag != null) _OldItem = (ListViewItem)_ListView.Tag;
ListViewItem _Item = _ListView.GetItemAt(e.X, e.Y);
if (_Item != null)
{
if (_OldItem != null && !_OldItem.Equals(_Item)) _OldItem.BackColor = _ListView.BackColor;
_Item.BackColor = Color.LightBlue;
_ListView.Tag = _Item;
}
else
{
if (_OldItem != null && !_OldItem.BackColor.Equals(_ListView.BackColor)) _OldItem.BackColor = _ListView.BackColor;
}
}