我使用的是設置以下參數ListView控件:提供了一些隨機文本在列表視圖與閃爍和的OwnerDraw virtualmode
this.listView1.BackColor = System.Drawing.Color.Gainsboro;
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.listView1.FullRowSelect = true;
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(67, 192);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(438, 236);
this.listView1.TabIndex = 0;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.DrawColumnHeader += new System.Windows.Forms.DrawListViewColumnHeaderEventHandler(this.listView1_DrawColumnHeader);
this.listView1.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.listView1_RetrieveVirtualItem);
this.listView1.DrawSubItem += new System.Windows.Forms.DrawListViewSubItemEventHandler(this.listView1_DrawSubItem);
兩行。自主提款很簡單:
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
if (e.ColumnIndex == 0)
{
e.DrawBackground();
e.DrawText();
}
else
e.DrawDefault = true;
//Console.WriteLine("{0}\t\tBounds:{1}\tItem:{2}\tSubitem:{3}", (i++).ToString(), e.Bounds.ToString(), e.Item, e.SubItem);
}
問題是:當我將鼠標懸停在listview的內容上時,我得到了第一列的閃爍。調試顯示DrawSubItem在鼠標懸停時被不斷調用。
這是錯誤嗎?如何避免這種行爲?
這是一個老問題,但被接受的答案是不正確的,或者至少不是.NET 4.0的。檢查ListView類的DoubleBuffered受保護屬性,並可能回答[this](http:// stackoverflow。com/questions/10484265/flickering-in-listview-control-ownerdraw-virtual/10501938#10501938)問題。 – zmilojko 2012-05-08 15:46:48
給出的答案是完全正確的。在XP上,如果您有虛擬列表並將鼠標懸停在第0列上,則控件將閃爍。 DoubleBuffered = true沒有區別。誠然,在Windows 7上,這個問題不會發生,但這並不會使這個答案不正確。 – Grammarian 2012-05-11 05:00:41