As mentioned in Solution 1, there are many other ways of doing this—most importantly, you can change the overall architecture of this too, make them click something else and then initiate the function on other two operations. That would be much simpler.
In the reflection, you can work around with the
EventInfo
objects to see when something happened and then delegate it. Microsoft has just the documentation for that part that lets you add a delegate to the event on runtime and then you can do what you wanted to (click on another button). See this,
How to: Hook Up a Delegate Using Reflection | Microsoft Docs[
^]
The main question is: How would you trigger the click event? Since there is no
btn.Click()
function, you are better going to use the
btn_Click
event handler to imitate as if you clicked the button. In that case, you would need to pass the parameters for that, a typical button handler requires,
public void btn_Click(object sender, EventArgs e) { }
So, you can do that using,
btn_Click(secondBtn, null);
Now, if you think this is ugly. You would then need to use some sort of UI automation script that does that for you. Apart from this, another solution won't be easier to take care of.
c# - Getting event via reflection - Stack Overflow[
^]