private void ltv_song_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { ColorConverter ColorCv = new ColorConverter(); Color clr = (Color)ColorCv.ConvertFromString("#5AC6E7"); SolidBrush sb = new SolidBrush(clr); e.Graphics.FillRectangle(sb, e.Bounds); using (StringFormat sf = new StringFormat()) { sf.Alignment = StringAlignment.Center; Color txtclr = (Color)ColorCv.ConvertFromString("#083947"); SolidBrush txtsb = new SolidBrush(txtclr); //e.Graphics.DrawImage(Record.Properties.Resources.listbt, e.Bounds); using (Font headerFont = new Font("宋体", 9, FontStyle.Regular)) { Rectangle rec = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 5, e.Bounds.Width, e.Bounds.Height + 10); e.Graphics.DrawString(e.Header.Text,ltv_song.Font,txtsb, rec, sf); } } } private void ltv_song_DrawItem(object sender, DrawListViewItemEventArgs e) { ColorConverter ColorCv = new ColorConverter(); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; //Rectangle rec = new Rectangle(e.Bounds.X + 3, e.Bounds.Y + 5, e.Bounds.Width, e.Bounds.Height + 10); // 绘制整个ListView 项目的背景。 if ((e.State & ListViewItemStates.Selected) != 0) { // 替一个被选取的项目绘制背景。#B2E4F4 Color clr = (Color)ColorCv.ConvertFromString("#27B6E2"); SolidBrush sb = new SolidBrush(clr); e.Graphics.FillRectangle(sb, e.Bounds); e.DrawFocusRectangle(); e.Graphics.DrawString(e.Item.Text, ltv_song.Font, sb, e.Bounds, sf); } else if (e.ItemIndex % 2 != 0) { // 替一个未被选取的项目绘制背景。#C6EAF6 Color clr = (Color)ColorCv.ConvertFromString("#C6EAF6"); SolidBrush sb = new SolidBrush(clr); e.Graphics.FillRectangle(sb, e.Bounds); e.Graphics.DrawString(e.Item.Text, ltv_song.Font, sb, e.Bounds, sf); } // 替详细数据检视模式以外的检视模式绘制项目文字。 if (!(this.ltv_song.View == View.Details)) { e.DrawText(); } } private void ltv_song_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { e.DrawText(); } private void ltv_song_MouseMove(object sender, MouseEventArgs e) { ListViewItem item = ltv_song.GetItemAt(e.X, e.Y); if (item != null && item.Tag == null) { ltv_song.Invalidate(item.Bounds); item.Tag = "taggg"; } } private void ltv_song_MouseUp(object sender, MouseEventArgs e) { ListViewItem clickedItem = this.ltv_song.GetItemAt(5, e.Y); if (clickedItem != null) { clickedItem.Selected = true; clickedItem.Focused = true; } } private void ltv_song_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (ltv_song.SelectedItems.Count > 0) { //ltv_song.ContextMenuStrip = menustrip_delete; } else { ltv_song.ContextMenuStrip = null; } } }
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/articles/1524837.html,如需转载请自行联系原作者