mercredi 21 février 2018

Invoke Event Handler via Reflection

I'm trying to invoke an event handler using reflection, but I keep getting the following error:

enter image description here

I'm assuming it's because of the arguments the function uses, but I'm really not sure. Code to get the method:

((Label)pControl).Background = m_pBrush;
string sControlName = ((Control)pControl).Name;
string sFuntionName = sControlName + "_MouseDoubleClick";

MethodInfo pMethod = this.GetType()?.GetMethod(sFuntionName);
pMethod.Invoke(((Label)pControl), null);

One of the functions it may find is public void lblShowLeaks_MouseDoubleClick(object sender, MouseButtonEventArgs e), so I tried creating a MouseButtonEventArgs object but I can't figure out how to grab the needed MouseDevice object needed by the constructor.

I've never used reflection before, so any help is appreciated.





Aucun commentaire:

Enregistrer un commentaire