Bob Dylan
Bob Dylan

Reputation: 4453

How to communicate between a user control and my main form?

I have a few (1-3) user controls on my form. I want to be able to click a button on my form (that is not part of the user controls) and have all 3 of my user controls respond. How can I do this?

Upvotes: 1

Views: 2070

Answers (1)

djdd87
djdd87

Reputation: 68456

If I understand you correctly, this is all you need to do; just add a public method to your user control and call that method from your button press:

protected void Button_Click(object sender, EventArgs e)
{
   UserControl1.DoMethod();
   UserControl2.DoMethod();
   UserControl3.DoMethod();
}

public class YourUserControl : UserControl
{ 
   public void DoMethod()
   {
      // Show your ListBoxes
   }
}

Upvotes: 4

Related Questions