It's possible to make a control in a Form public, but not recommended, you can do the following:
1) Declare a new event in the first form (form1) ButtonFirstFormClicked
public event EventHandler ButtonFirstFormClicked;
and trigger this event in the Button.Click event handler
void button_Clicked(object sender, EventArgs e)
{
// if you're working with c# 6.0 or greater
ButtonFirstFormClicked?.Invoke(sender, e);
// if you're not then comment the above method and uncomment the below
//if (ButtonFirstFormClicked!= null)
// ButtonFirstFormClicked(sender, e);
}
2) In the second form (form2) subscribe the event
form1.ButtonFirstFormClicked += (s, e)
{
// put your code here...
}
Good luck!
answered 2010-11-05T23:14:05.617