How do I suspend painting for a control and its children?

前端 未结 10 1952
小鲜肉
小鲜肉 2020-11-22 01:34

I have a control which I have to make large modifications to. I\'d like to completely prevent it from redrawing while I do that - SuspendLayout and ResumeLayout aren\'t eno

10条回答
  •  再見小時候
    2020-11-22 02:05

    A nice solution without using interop:

    As always, simply enable DoubleBuffered=true on your CustomControl. Then, if you have any containers like FlowLayoutPanel or TableLayoutPanel, derive a class from each of these types and in the constructors, enable double buffering. Now, simply use your derived Containers instead of the Windows.Forms Containers.

    class TableLayoutPanel : System.Windows.Forms.TableLayoutPanel
    {
        public TableLayoutPanel()
        {
            DoubleBuffered = true;
        }
    }
    
    class FlowLayoutPanel : System.Windows.Forms.FlowLayoutPanel
    {
        public FlowLayoutPanel()
        {
            DoubleBuffered = true;
        }
    }
    

提交回复
热议问题