Windows Forms: using BackgroundImage slows down drawing of the Form's controls

后端 未结 6 1579
终归单人心
终归单人心 2020-12-08 02:33

I have a Windows Form (C# .NET 3.5) with a number of buttons and other controls on it, all assigned to a topmost Panel which spans the whole Form. For example, the hierarchy

6条回答
  •  时光取名叫无心
    2020-12-08 03:25

    Another very simple way to avoid permanent redraws while adding your controls is to make the parent control invisible before you add controls to it. Afterwards you make the parent control (for example, a panel) visible and there it is without all those repaints. :-)

    panelParent.visible = false;
    
    for(...) {
        // Add your controls here:
        panelParent.Controls.Add(...);
    }
    
    panelParent.visible = true;
    

提交回复
热议问题