Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add user control to panel

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, userControl1 will be added to panel after removing every control on it and so on.

I have this code :

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

but it's not working.

How I can do it?

like image 582
Saleh Avatar asked Mar 18 '12 23:03

Saleh


1 Answers

You have to instantiate your controls. You will have to make sure the size is set appropriately, or for it to have an appropriate dockfill.

var myControl = new MyProject.Modules.Masters();
panel1.Controls.Add(myControl);
like image 182
Justin Pihony Avatar answered Sep 30 '22 01:09

Justin Pihony