Jam*_*mes 3 .net c# listview winforms
我有一个 System.Windows.Forms.ListView 包含许多项目。它闪烁得令人无法忍受(似乎经常是这种情况),所以经过一番搜索后,我决定在“ListViewLessFlicker”类中做这两件事。
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
Run Code Online (Sandbox Code Playgroud)
尽管 DoubleBuffering 在这些主题中最常作为解决方案给出,但它并没有太大影响,但将样式设置为不透明,真正大大减少了闪烁。
http://www.virtualdub.org/blog/pivot/entry.php?id=273
然而,它有一个副作用,我似乎无法找到解决办法。当我将鼠标悬停在 ListView 中的一个项目上时,它现在使文本变得粗体且非常模糊(除非 opaque 为真,否则不会发生这种情况)。
这是一个非常放大的示例。
如果有人有修复方法或知道为什么会这样做,我很想知道!
我通常这样做 - 在调整控件大小时减少闪烁。批量添加项目时,您需要使用BeginUpdate()
/EndUpdate()
来减少闪烁。我不知道是什么导致了模糊,所以我不能就此提出建议 - 更新您的视频驱动程序可能会有所帮助,但不要抱太大希望。
[System.ComponentModel.DesignerCategory ( "" )]
public partial class ListViewEx : ListView
{
private const int WM_ERASEBKGND = 0x14;
public ListViewEx ()
{
InitializeComponent ();
// Turn on double buffering.
SetStyle ( ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, true );
// Enable the OnNotifyMessage to filter out Windows messages.
SetStyle ( ControlStyles.EnableNotifyMessage, true );
}
protected override void OnNotifyMessage ( Message oMsg )
{
// Filter out the WM_ERASEBKGND message to prevent the control
// from erasing the background (and thus avoid flickering.)
if ( oMsg.Msg != WM_ERASEBKGND )
base.OnNotifyMessage ( oMsg );
}
}
Run Code Online (Sandbox Code Playgroud)