First of all, remove all the public stuff (event handlers and controls) that you've done as that is not the solution to your problem.
Why do you need to know which button was pressed? I can't imagine a scenario where that would be needed.
If you need a
Button
to
Click in
Form
due to something happening in
Form2
then
Form2
should raise an event that
Form
subscribes to, and in the handler for that event it should either call the handler for the
Button
's
Click
or call the
Button
's
PerformClick()
method.
public event EventHandler ReclickRequest;
private void WhateverItIsThatCausesThis()
{
OnReclickRequest(EventArgs.Empty);
}
protected virtual void OnReclickRequest(EventArgs e)
{
EventHandler eh = ReclickRequest;
if(eh != null)
eh(this, e);
}
Form2 form2 = new Form2();
form2.ReclickRequest = form2_ReclickRequest;
private void form2_ReclickRequest(object sender, EventArgs e)
{
}
See
here[