Correct implementation of EventHandler without parameters
Juan Carlos Rendon
1
Reputation point
I am working with events in C# and have been trying to remove the warnings for the correct event declaration. According to several articles that I have read first that delcara is a delegate that in this case has no input parameters, then the event is declared and fired. You also have to make a subscription to the event. The problem is that the warning I'm trying to remove tells me to declare the first parameter as an object called sender and the second parameter as EventArgs called e. But not to solve it I must make both parameters be or inherit from the type object and EventArgs.
public delegate void BringMainFormToFront();
public static event BringMainFormToFront BringMainToFrontEvent;
public static void OnBringMainToFront()
{
BringMainToFrontEvent?.Invoke();
}
public MainForm()
{
BringMainToFrontEvent += BringMainToFront;
}
Community Center Not monitored
46,181 questions
Sign in to answer