So I have a class made specifically for holding an event handling method which I want to use in multiple other classes:
class MyHandler
{
public MyHandler()
{
}
public void Method1(object sender, EventArgs e)
{
}
}
Now if i do:
button1.Click += new System.EventHandler(this, MyHandler.Method1);
I get the error mentioned in the title. What am I doing wrong here?
It’s not clear what your arguments are meant to be for. If the event subscription code is within an instance method of
MyHandleryou just want:or more briefly:
If it’s from a different class, you either need to create an instance of
MyHandler, e.g.or make the
Method1method static and subscribe like this: