Click here to Skip to main content
16,016,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write application in C#.This application is Win forms.
I add menu strip in that form.Add new and close sub items in that from.
I add 1 panel in that form.

When I click new menu item one user control(UserControl1 ) add to panel.In that UserControl1 have one "Ok" botton.
I want that I want add another user control (UserControl2) to same panel of form in "Ok" button click event.

Can any one give me solution.

Thank You!
Posted

1 solution

It ain't rocket science...

C#
class MyForm
{
   MyUserControl myUserControl = null;
  
   private void buttonClickEvent(object sender, EventArgs e)
   {
       myUserControl = new MyUserControl();
   }
}
 
Share this answer
 
Comments
kailas_khule 7-Dec-10 6:30am    
This answer is in Same Event Click, but where to add user control to panel.
kailas_khule 7-Dec-10 6:34am    
Here I add user Control to from

objUserControl1 = new UserControl1();

this.panel1.Controls.Clear();
this.panel1.Controls.Add(objUserControl1);


But UserControl1 button click event I want add another UserControl2 to Panel1.
Manfred Rudolf Bihy 7-Dec-10 9:10am    
Have another handler:
private void uc_buttonClick(object sender, EventArgs e)
{
UserControl uc2 = new UserControl();
this.panel1.Controls.Add(uc2);
}

and in your first event handler do a:
objUserControl1.eventNameForYourOkButtonOnYourControl += new EventHandlerForYourOKButton(uc_buttonClick);

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