simple custom event

后端 未结 4 1772

I\'m trying to learn custom events and I have tried to create one but seems like I have a problem

I have created a Form, static class and custom event. What I\'m tr

4条回答
  •  日久生厌
    2020-11-27 12:21

    You haven't created an event. To do that write:

    public event EventHandler Progress;
    

    Then, you can call Progress from within the class where it was declared like normal function or delegate:

    Progress(this, new Progress("some status"));
    

    So, if you want to report progress in TestClass, the event should be in there too and it should be also static. You can the subscribe to it from your form like this:

    TestClass.Progress += SetStatus;
    

    Also, you should probably rename Progress to ProgressEventArgs, so that it's clear what it is.

提交回复
热议问题