winform 控件闪烁的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/beibeisong/article/details/50553477

控件拖拽大小、位置,出现了一个现象就是会存在闪烁的问题,查阅资料,整理了下网上解决闪烁的方法


一、解决winform窗体闪烁


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

二、panel等控件闪烁,下面已panel控件为例


1、自己重写控件

class ucPanel : Panel
    {
        public ucPanel()
        {
            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
        }
    }
2、

ucPanel.GetType().GetProperty("DoubleBuffered", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(parent, truenull);
3、某些特殊情况需要1、2两种方法,具体原因还不清楚

猜你喜欢

转载自blog.csdn.net/beibeisong/article/details/50553477
今日推荐