简体   繁体   中英

open c# user control from another user control

I have ac# 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

You have to create the control you want to add and add it.

YourCustomControl uc = null;

private void button1_Click(object sender, EventArgs e)
{
     uc = new YourCustomControl();
     this.Controls.Add(uc); // this represent the user control in which you want to add
                            // You can add it in some container like Panel or GroupBox
}

Take a look at RaiseBubbleEvent . This pushes an event up to its parent.

http://msdn.microsoft.com/en-us/library/aa719644(v=vs.71).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM