I want to create some engine for monogame in C #. My engine should include a button. I want to do this with events. Basically, I did it, but I want to improve it, and my problems started.
class Button : Component
{
....
public event EventHandler<EventArgs> Click;
public void OnClick()
{
if (MousePressed() && Click != null)
{
Click(this, new EventArgs());
}
}
}
and when I want to add a Click event, I have to do it in another class:
_buttnon.Click += new EventHandler<EventArgs>(Method);
_buttnon.OnClick();
This works well, but I want to do it like this:
_button.RegisterClickEvent(Method);
so I added Button class code below:
public void RegisterClickEvent(XXX method) {
Click += new EventHandler<EventArgs>(method);
}
I absolutely do not know that I need to replace XXX. I tried:
public void RegisterClickEvent(void(object, EventArgs)method) {
Click += new EventHandler<EventArgs>(method);
}
but it does not work. I tried to find something on Google, but I don't know what I'm looking for.
source
share