我有一个继承的列表视图,当我单击列标题时有明显的闪烁。该列表在详细信息视图中。
public ListViewEx()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
this.DoubleBuffered = true;
}
int sortColumn = -1;
protected override void OnColumnClick(ColumnClickEventArgs e)
{
if(e.Column != sortColumn)
{
sortColumn = e.Column;
this.Sorting = SortOrder.Ascending;
}
else
{
if(this.Sorting == SortOrder.Ascending)
this.Sorting = SortOrder.Descending;
else
this.Sorting = SortOrder.Ascending;
}
this.Sort();
}
填充列表时没有闪烁。
for(int i = 0; i < 10; i++)
{
ListViewItem lvi = new ListViewItem("this is column 1 " +i);
lvi.SubItems.Add("...
lvi.SubItems.Add("...
lvi.SubItems.Add("...
lvi.SubItems.Add("...
lvi.SubItems.Add("...
listViewEx1.Items .Add (lvi);
}
编辑 WM_ERASEBKGND 没有解决我的问题。
我在托管列表视图的表单中添加了这段代码,闪烁消失了
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}