What you can do is create a static event in another class and then get form 1 to subscribe to the event. Then, when the button is pressed in Form 2, raise the event for Form 1 to select.
You can declare an event in Form 1 if you wish.
public class Form1 : Form
{
public static event EventHandler MyEvent;
public Form1()
{
Form1.MyEvent += new EventHandler(MyEventMethod);
}
private void MyEventMethod(object sender, EventArgs e)
{
}
public static void OnMyEvent(Form frm)
{
if (MyEvent != null)
MyEvent(frm, new EventArgs());
}
}
public class Form2 : Form
{
private void SaveButton(object sender, EventArgs e)
{
Form1.OnMyEvent(this);
}
}
source
share