Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Dear Sir/Madam

I have a Form1 in my C# Project. Within this project I haved added a UserControl. Now my question is:

How can i show the UserControl from Form1 by clicking the button,
(the similarity would be like: e.g...)

form1 frm = new form1();

frm.show();


But for UserControl this is not working.
Please any help would be very greatfull.

Thanks in advance


Roni
Posted
Comments
Manfred Rudolf Bihy 21-Nov-10 15:19pm    
Is the user control already on the form or do you want to add it dynamically?
If you want to add it dynamically use Heinzzy's or OriginalGriff's answer.
Sandeep Mewara 22-Nov-10 0:43am    
Update from OP:
the UserControl is not in the form, i want to call it dynamically...


kind regards

roni

MyUserControl myControl1 = new MyUserControl();
frm.Controls.Add(myControl1);
 
Share this answer
 
Try:
MyUserControl muc = new MyUserControl();
muc.Location = pointIWantItAt;
Controls.Add(muc);
This add the user control to the current class (form) Controls list, and this will make it visible.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900