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

前端 未结 10 1927
小鲜肉
小鲜肉 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 01:43

    To help with not forgetting to reenable drawing:

    public static void SuspendDrawing(Control control, Action action)
    {
        SendMessage(control.Handle, WM_SETREDRAW, false, 0);
        action();
        SendMessage(control.Handle, WM_SETREDRAW, true, 0);
        control.Refresh();
    }
    

    usage:

    SuspendDrawing(myControl, () =>
    {
        somemethod();
    });
    

提交回复
热议问题