Search code examples
c#c#-4.0user-controls

How to reload usercontrol from another form


I have two forms, Form1 and Form2

form1 containing usercontrol1, whereas form 2 containing button1.

Issue: I want to reload usercontrol1 when button 1 is clicked. I've written some code but got an error,don't know what should I do to fix this.

 private void button1_Click(object sender, EventArgs e)
        {  
         UserControl1 master = (UserControl1)Application.OpenForms["UserControl1"];
          master.UserControl1_Load();
        }

Any help will be appreciated.


Solution

  • i tried this and it's work perfectly.

    in Form1.designer.cs

     public UserControl1 userControl11;
    

    in Form2

     private void button1_Click(object sender, EventArgs e)
    {
        Form1 master = (Form1)Application.OpenForms["Form1"];
        master.userControl1.UsrControl1_Load();
    }
    

    in userControl1.cs

      public void UsrCont1_Load()
     {
       UserControl1_Load(this, null);
     }