I have a function in form1 and it perfectly works for finding ButtonName_click event handlers in form1.
However, it can not find event handlers for buttons in usercontrols.
private void Implement_Button_Click(Control Button)
{
MethodInfo clickMethod = this.GetType()
.GetMethod(Button.Name + "_Click",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
null,
new Type[] { typeof(object), typeof(EventArgs) },
null);
var args = new object[] {
this,
(object)EventArgs.Empty
};
clickMethod.Invoke(this, args);
this function is in form1. So, this.Gettype() would be Form1.Gettype() …
I would like to look into all usercontrols for such event handlers.
Although passing usercontrols instance to the function would solve my issue, I am looking for a way to circumvent passing the usercontrol eachtime I call this function.(It is a very annoying solution for me)
How should I modify this function?