C#解决动态显示控件闪烁,使Windows Forms启用双缓冲于所有窗体以及其子控件就不闪了。

 在SDK头文件中有这样一个Windows样式:WS_EX_COMPOSITED,这个样式可使Windows Forms启用双缓冲于所有窗体以及其子控件。

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

网上说的不对。

        public Form1()
        {
            InitializeComponent();
            base.SetStyle(
            ControlStyles.OptimizedDoubleBuffer
            | ControlStyles.ResizeRedraw
            | ControlStyles.Selectable
            | ControlStyles.AllPaintingInWmPaint // 禁止擦除背景.
            | ControlStyles.UserPaint
            | ControlStyles.SupportsTransparentBackColor
            | ControlStyles.DoubleBuffer  // 双缓冲
            ,true);
        }

猜你喜欢

转载自blog.csdn.net/chenhao0568/article/details/107746845