代码之家  ›  专栏  ›  技术社区  ›  Mahesh

调整窗体大小时WinForm UI上闪烁

  •  1
  • Mahesh  · 技术社区  · 7 年前

    当我调整winformui(有很多子控件)的大小时,会出现闪烁。

    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
            cp.Style &= ~0x02000000;// Turn off WS_CLIPCHILDREN
            return cp;
        }
    }
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   Baltasarq    7 年前

    创建 这将是你所有孩子的根源 形式 ,在你的 形式 . 方法,调用 控制 SuspendLayout() ;在 形式 OnResizeEnd() 控制 简历布局()

    class MainForm: Form {
        public MainForm()
        {
            this.Build();
        }
    
        void Build()
        {
            this.root =  new Panel { Dock = DockStyle.Fill };
            // create all controls and add them to root
    
            this.Controls.Add( root );
            this.ResizeBegin += (obj, args) => this.OnResizeBegin();
            this.ResizeEnd += (obj, args) => this.OnResizeEnd();
        }
    
        void OnResizeBegin()
        {
            this.root.SuspendLayout();
        }
    
        void OnResizeEnd()
        {    
            this.root.ResumeLayout( true );
        }
    
        Panel root;
    }
    

    希望这有帮助。

        2
  •  0
  •   GuidoG    7 年前


    你也应该使用 |= &=

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

    如果你的表格上还有部分不停地闪烁,那么也许吧 this post