private int counter = 0;
public Form1()
...{
InitializeComponent();
}
DoubleBufferListView lv = new DoubleBufferListView();
ListView lv = new ListView();
private void Form1_Load(object sender, EventArgs e)
...{
timer1.Enabled = false;
this.Controls.Add(lv);
lv.View = View.Details;
lv.GridLines = true;
lv.BackColor = Color.Silver;
lv.Columns.Add("aa");
lv.Columns.Add("bb");
lv.Columns.Add("cc");
lv.Height = 300;
lv.Width = 300;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
...{
lv .Items.Add(counter.ToString());
counter++;
}
}
解决方法:
使用双缓冲,重写listview
class DoubleBufferListView : ListView
...{
public DoubleBufferListView()
...{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
}
public partial class Form1 : Form
...{
private int counter = 0;
public Form1()
...{
InitializeComponent();
}
DoubleBufferListView lv = new DoubleBufferListView();
private void Form1_Load(object sender, EventArgs e)
...{
timer1.Enabled = false;
this.Controls.Add(lv);
lv.View = View.Details;
lv.GridLines = true;
lv.BackColor = Color.Silver;
lv.Columns.Add("aa");
lv.Columns.Add("bb");
lv.Columns.Add("cc");
lv.Height = 300;
lv.Width = 300;
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
...{
lv .Items.Add(counter.ToString());
counter++;
}
效果是不是很明显啊?呵呵。