Remove all controls in a flowlayoutpanel in C#

前端 未结 4 1259
名媛妹妹
名媛妹妹 2021-02-10 01:45

I\'m building a flow layout panel whose each control represents for a room. I want to reload all room by removing all controls in the panel and adding new controls.

I us

4条回答
  •  春和景丽
    2021-02-10 01:48

    According to MSDN, you can clear all controls from a ControlCollection (such as a FlowLayoutPanel) by calling the Clear() method. For example:

    flowLayoutPanel1.Controls.Clear();
    

    Be aware: just because the items are removed from the collections does not mean the handlers are gone and must be disposed of properly less you face memory leaks.

提交回复
热议问题