public class DoubleBufferListView : ListView
{
public DoubleBufferListView()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}
{
public DoubleBufferListView()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int ViewSel { get; set; }
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void CreateListView()
{
}
private void timer1_Tick(object sender, EventArgs e)
{
listView1.BeginUpdate();
listView1.Clear();
ListViewItem lItem;
this.listView1.Alignment = ListViewAlignment.Default;
for (int i = 0; i < 80; i++)
{
//Application.DoEvents();
lItem = new ListViewItem();
lItem.Text = DateTime.Now.Second + "_test";
lItem.Tag = i;
lItem.ImageIndex = i % 2;
lItem.ToolTipText = "空间" + i;
listView1.Items.Add(lItem);
}
listView1.Items[ViewSel].Selected = true;
listView1.EndUpdate();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
ViewSel = listView1.SelectedItems[0].Index;
this.Text = listView1.SelectedItems[0].ToolTipText;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public int ViewSel { get; set; }
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void CreateListView()
{
}
private void timer1_Tick(object sender, EventArgs e)
{
listView1.BeginUpdate();
listView1.Clear();
ListViewItem lItem;
this.listView1.Alignment = ListViewAlignment.Default;
for (int i = 0; i < 80; i++)
{
//Application.DoEvents();
lItem = new ListViewItem();
lItem.Text = DateTime.Now.Second + "_test";
lItem.Tag = i;
lItem.ImageIndex = i % 2;
lItem.ToolTipText = "空间" + i;
listView1.Items.Add(lItem);
}
listView1.Items[ViewSel].Selected = true;
listView1.EndUpdate();
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
ViewSel = listView1.SelectedItems[0].Index;
this.Text = listView1.SelectedItems[0].ToolTipText;
}
}
}
}
namespace WindowsFormsApplication1
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.listView1 = new WindowsFormsApplication1.DoubleBufferListView();
this.SuspendLayout();
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "示例图片_03.jpg");
this.imageList1.Images.SetKeyName(1, "示例图片_02.jpg");
this.imageList1.Images.SetKeyName(2, "示例图片_04.jpg");
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// listView1
//
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.LargeImageList = this.imageList1;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.Name = "listView1";
this.listView1.ShowItemToolTips = true;
this.listView1.Size = new System.Drawing.Size(292, 266);
this.listView1.SmallImageList = this.imageList1;
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.listView1);
this.DoubleBuffered = true;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.Timer timer1;
private DoubleBufferListView listView1;
}
}
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.listView1 = new WindowsFormsApplication1.DoubleBufferListView();
this.SuspendLayout();
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "示例图片_03.jpg");
this.imageList1.Images.SetKeyName(1, "示例图片_02.jpg");
this.imageList1.Images.SetKeyName(2, "示例图片_04.jpg");
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// listView1
//
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.LargeImageList = this.imageList1;
this.listView1.Location = new System.Drawing.Point(0, 0);
this.listView1.Name = "listView1";
this.listView1.ShowItemToolTips = true;
this.listView1.Size = new System.Drawing.Size(292, 266);
this.listView1.SmallImageList = this.imageList1;
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.listView1);
this.DoubleBuffered = true;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.Timer timer1;
private DoubleBufferListView listView1;
}
}