What does Button.PerformClick do?

后端 未结 1 1304
轻奢々
轻奢々 2021-01-19 09:46

I know this might be a trivial question, but I was just wondering whether there is any advantage of calling Button.PerformClick rather than invoking the click event of a but

相关标签:
1条回答
  • 2021-01-19 10:02

    An external caller who knows nothing of the subscribed events cannot simply call the click handler - and events do not allow you to obtain information about subscribers. So this method allows separation of concerns, so that external callers can "play nice".

    Additionally:

    • it ensures that any polymorphism on the virtual method is applied
    • it applies any rules - for example: is the button disabled

    If you do know about the event-handler, and you aren't using polymorphism, and you don't care whether it is disabled, and you don't need to worry about event-handlers you don't already know about - then by all means : just call the event-handler method.

    0 讨论(0)
提交回复
热议问题