Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
1.18/5 (3 votes)
See more:
hello,

I have a c# user control. I have a button in this control, and I want that when the user clicks on the button, another user control will be opened.

How can I do that?

Thanks
Posted
Updated 24-May-17 10:26am
v2

What user control is that?
Is it a Windows Application or Web Application?
You can use Properties of Visible to hide or show the control.
C#
protected void Button1_Click(object sender, EventArgs e)
{
    userControl1.Visible = !userControl1.Visible;
}
 
Share this answer
 
v2
I don't understand what you mean with 'open user control', but you can show, hide, add and remove controls.

Show controls[^]
Hide controls[^]
Add controls[^]
Remove controls[^]
 
Share this answer
 
Please try the following code

Window win = new Window();
UserControl1 eDoc = new UserControl1();
win.Content = eDoc;
win.Title = "User Control1";
win.Show();


Hope be helpful,
Theingi
 
Share this answer
 
In your button click event, create a control and add it in the collection

C#
myOwnControl userControl1 = new myOwnControl ();
this.Controls.Add(userControl1);


-Milind
 
Share this answer
 
Comments
Member 14167697 2-Mar-19 16:44pm    
Can you give more information about this? Where do you get the Controls property and how to use it? Thank you in advance.

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