winform重新加载treeview时,出现闪烁

来源:互联网 发布:淘宝气值是什么意思 编辑:程序博客网 时间:2024/06/14 16:07

借鉴网上代码

protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }

闪烁消失,但打开软件第一瞬间有黑框出现,正在考虑解决

自定义 ListView 

/// <summary>
    ///  启用双缓存,避免ListView控件加载数据时闪烁
    /// </summary>
    public class MyListView : ListView
    {
        public MyListView()
        {
            // 开启双缓冲
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.EnableNotifyMessage, true);
        }


        protected override void OnNotifyMessage(Message m)
        {
            if (m.Msg != 0x14)
            {
                base.OnNotifyMessage(m);
            }
        }
    }

原创粉丝点击