改善加载画面时闪烁

        private PropertyInfo _PropertyInfo = null;
        bool isNeedCreateDBMakerRegistry = false;
        public L10()
        {
            try
            {
                InitializeComponent();
                #region 改善加载画面时闪烁
                this.DoubleBuffered = true;//设置本窗体
                SetStyle(ControlStyles.UserPaint, true);
                SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
                SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
                this._PropertyInfo = this.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
                foreach (Control rootCtrl in this.Controls)
                {
                    this._PropertyInfo.SetValue(rootCtrl, true, null);

                    if (rootCtrl.HasChildren)
                        SearchControl(rootCtrl);
                }
                #endregion
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }
        /// <summary>
        /// 查找子控件
        /// </summary>
        /// <param name="Ctrl"></param>
        void SearchControl(Control Ctrl)
        {
            foreach (Control rootCtrl in Ctrl.Controls)
            {
                this._PropertyInfo.SetValue(rootCtrl, true, null);
                if (rootCtrl.HasChildren)
                    SearchControl(rootCtrl);
                else
                    break;
            }
        }

        public L10(bool isNeedCreateDBMakerRegistry = false)
        {
            InitializeComponent();
            this.isNeedCreateDBMakerRegistry = isNeedCreateDBMakerRegistry;
            #region 改善加载画面时闪烁
            this.DoubleBuffered = true;//设置本窗体
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲说
            this._PropertyInfo = this.GetType().GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
            foreach (Control rootCtrl in this.Controls)
            {
                this._PropertyInfo.SetValue(rootCtrl, true, null);

                if (rootCtrl.HasChildren)
                    SearchControl(rootCtrl);
            }
            #endregion
        }

猜你喜欢

转载自www.cnblogs.com/6B23/p/12206365.html
今日推荐