C#中更新列表视图闪烁 [英] c# flickering Listview on update

查看:263
本文介绍了C#中更新列表视图闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个定期更新的列表视图(每60秒)。它是烦人,我认为我将每一次它过时获得闪烁。所采用的方法是清除所有的项目,然后重新创建它们。我决定,而不是结算的项目,我只想直接写入新文本的单元格。这是一个更好的方法或有没有人有一个更好的解决方案。

I have a list view that is periodically updated (every 60 seconds). It was anoying to me that i would get a flicker every time it up dated. The method being used was to clear all the items and then recreate them. I decided to instead of clearing the items I would just write directly to the cell with the new text. Is this a better approach or does anyone have a better solution.

推荐答案

ListView控件有一个闪烁的问题。这个问题似乎是在控制的更新超载不正确实施,使得它就像一个刷新。最新情况应引起,而刷新重绘控件的整个客户区控制重绘只对其无效的区域。所以,如果你要改变,比如说,一个项目的背景颜色列表中,则只有特定项目应该需要重新绘制。不幸的是,ListView控件似乎是一个不同的意见,并希望每当即使没有当前显示的项目你惹单个项目...重绘其整个表面。所以,不管怎么说,你可以很容易地燮preSS滚动自己的闪烁如下:

The ListView control has a flicker issue. The problem appears to be that the control's Update overload is improperly implemented such that it acts like a Refresh. An Update should cause the control to redraw only its invalid regions whereas a Refresh redraws the control’s entire client area. So if you were to change, say, the background color of one item in the list then only that particular item should need to be repainted. Unfortunately, the ListView control seems to be of a different opinion and wants to repaint its entire surface whenever you mess with a single item… even if the item is not currently being displayed. So, anyways, you can easily suppress the flicker by rolling your own as follows:

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#中更新列表视图闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆