What does Button.PerformClick do?

I know this may be a trivial question, but I'm just wondering if there is any advantage in calling Button.PerformClick , and not when calling, click the button event directly. The MSDN documentation just says:

Raises the Click event for the button.

Does this mean that it just does the same thing as triggering a button click event, or is there some other special advantage?

+4
source share
1 answer

An external caller who does not know anything about signed events cannot simply call a click handler - and events do not allow you to receive information about subscribers. Thus, this method allows sharing problems, so that outside parties can "play well."

Additionally:

  • it provides the application of any polymorphism in a virtual method
  • he applies any rules - for example: the button is disabled

If you know about the event handler, and you do not use polymorphism, and you do not care if it is disabled, and you do not need to worry about event handlers that you do not yet know about - then by all means: just call the event handler method.

+12
source

Source: https://habr.com/ru/post/1496226/


All Articles