Search code examples
winformsuser-interfaceload

Difference between OnLoad method and Load event?


What is the difference between OnLoad method and Load event? I am developing WinForm controls. Should I register to Load event or override the OnLoad method? What are the advantages and the disadvantages of each one?


Solution

  • I'd go for overriding OnLoad, so you spare the CPU cycles to invoke the event handler.

    The general pattern is to override a method, if you inherit from a control; otherwise, subscribe to the event.

    But remember to call the base class' OnLoad method, because that's where the Load event invoked.