How to add user control to panel

后端 未结 3 2048
猫巷女王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 04:38

    You need to instantiate a new MyProject.Modules.Masters.

    MyProject.Modules.Masters myMasters = new MyProject.Modules.Masters()
    panel1.Controls.Add(myMasters);
    

    This will only add a new control to panel1. If you also want to clear everything out of the panel before adding the control like you said in the question, call this first:

    panel1.Controls.Clear();
    

提交回复
热议问题