rtuner
rtuner

Reputation: 2410

What does Button.PerformClick do?

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 button directly. The MSDN documentation simply says:

Generates a Click event for a button.

Does this mean it simply does the same thing as calling the click event of the button or is there some other special advantage?

Upvotes: 5

Views: 7167

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062830

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.

Upvotes: 13

Related Questions