How to double buffer .NET controls on a form?

后端 未结 12 1773
旧巷少年郎
旧巷少年郎 2020-11-22 16:21

How can I set the protected DoubleBuffered property of the controls on a form that are suffering from flicker?

12条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 17:04

    This caused me a lot of grief for two days with a third party control until I tracked it down.

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

    I recently had a lot of holes (droppings) when re-sizing / redrawing a control containing several other controls.

    I tried WS_EX_COMPOSITED and WM_SETREDRAW but nothing worked until I used this:

    private void myPanel_SizeChanged(object sender, EventArgs e)
    {
         Application.DoEvents();
    }
    

    Just wanted to pass it on.

提交回复
热议问题