这是MSDN的例程。 它是在选中的情况下,填充矩形,绘制选中边框。你换成你的绘图代码就可以。。要注意处理不同的情况。。 private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e) { if ((e.State & ListViewItemStates.Selected) != 0) { // Draw the background and focus rectangle for a selected item. e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds); e.DrawFocusRectangle(); } else { // Draw the background for an unselected item. using (LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, Color.Orange, Color.Maroon, LinearGradientMode.Horizontal)) { e.Graphics.FillRectangle(brush, e.Bounds); } } // Draw the item text for views other than the Details view. if (listView1.View != View.Details) { e.DrawText(); } }
它是在选中的情况下,填充矩形,绘制选中边框。你换成你的绘图代码就可以。。要注意处理不同的情况。。
private void listView1_DrawItem(object sender,
DrawListViewItemEventArgs e)
{
if ((e.State & ListViewItemStates.Selected) != 0)
{
// Draw the background and focus rectangle for a selected item.
e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
e.DrawFocusRectangle();
}
else
{
// Draw the background for an unselected item.
using (LinearGradientBrush brush =
new LinearGradientBrush(e.Bounds, Color.Orange,
Color.Maroon, LinearGradientMode.Horizontal))
{
e.Graphics.FillRectangle(brush, e.Bounds);
}
} // Draw the item text for views other than the Details view.
if (listView1.View != View.Details)
{
e.DrawText();
}
}
你换台电脑或删除C:/imgList.bmp 试一下