How to add user control to panel

后端 未结 3 2082
猫巷女王i
猫巷女王i 2021-02-20 04:38

I have created multiple user controls in my project and what I need to do is to be able to switch between them on a panel control.

for example, if the user click button1

3条回答
  •  长情又很酷
    2021-02-20 05:03

    Isn't just easier.

    panel1.Controls.Clear();
    panel1.Controls.Add(new MyProject.Modules.Masters());
    

    EDIT: Maybe try this...

    panel1.Controls.Cast().ForEach(i => i.Dispose());
    panel1.Controls.Clear();
    panel1.Controls.Add(new MyProject.Modules.Masters());
    

提交回复
热议问题