c#更新时闪烁的Listview

标签 c# listview flicker

我有一个定期更新的 ListView (每 60 秒)。每次更新时我都会闪烁,这对我来说很烦人。使用的方法是清除所有项目,然后重新创建它们。我决定不清除项目,而是直接将新文本写入单元格。这是更好的方法还是有人有更好的解决方案。

最佳答案

ListView 控件存在闪烁问题。问题似乎是控件的 Update 重载未正确实现,因此它的行为类似于刷新。 Update 应该使控件仅重绘其无效区域,而 Refresh 重绘控件的整个客户区。因此,如果您要更改列表中某个项目的背景颜色,那么只需要重新绘制该特定项目。不幸的是,ListView 控件似乎有不同的意见,它希望在您弄乱单个项目时重新绘制其整个表面……即使当前未显示该项目。因此,无论如何,您可以按如下方式自己滚动来轻松抑制闪烁:

class ListViewNF : System.Windows.Forms.ListView
{
    public ListViewNF()
    {
        //Activate double buffering
        this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);

        //Enable the OnNotifyMessage event so we get a chance to filter out 
        // Windows messages before they get to the form's WndProc
        this.SetStyle(ControlStyles.EnableNotifyMessage, true);
    }

    protected override void OnNotifyMessage(Message m)
    {
        //Filter out the WM_ERASEBKGND message
        if(m.Msg != 0x14)
        {
            base.OnNotifyMessage(m);
        }
    }
}

发件人:Geekswithblogs.net

关于c#更新时闪烁的Listview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/442817/

相关文章:

android - OutOfMemoryError 在 ListView 中使用 ArrayAdapter

exception - 引导工具提示 "Uncaught TypeError: Cannot read property ' 触发器'为空"

delphi - 如何处理WM_ERASEBKGND以避免闪烁?

c# - 算法求助!与伙伴一起搜索字符串的快速算法

c# - 将字符串解析为 float C#

c# - 在 Entity Framework Core 中创建非聚集索引

java - 为什么我的列表没有填充到 Android Studio 中?

c# - 将数据从 SQLite 数据库输入 ListView

wxPython listctrl 快速更新闪烁

c# - 找不到“位图”(是否缺少 using 指令或程序集引用?)