Correct implementation of EventHandler without parameters

Juan Carlos Rendon 1 Reputation point
2020-08-04T12:29:20.95+00:00

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
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.