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?
相关问题
- How do I bind a DataGridViewComboBoxColumn to a pr
- Partial Form Class C# - Only display code view for
- JFX scale image up and down to parent
- Can we add four protocols to ServicePointManager.S
- How to properly handle form closing when using bac
相关文章
- Sort TreeView Automatically Upon Adding Nodes
- Where does this quality loss on Images come from?
- Missing partial modifier on declaration of type
- Algorithm for maximizing coverage of rectangular a
- Is there a way to hide the new HTML5 spinbox contr
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- PropertyGrid - Possible to have a file/directory s
- Programming a touch screen application with SWING
OnLoad is the default event handler used in VB.NET to handle the Load event. I typically override this method when I need to attach code to the load event. There are also default functions for the other Page Life Cycle events: OnPreRender, OnInit, etc.
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 theLoad
event invoked.OnLoad method is the one that raises Load event. It's a standard pattern in framework classes, and a generally recommended one - for any event
Foo
, you have a virtual protected methodOnFoo
which raises that event; and no other method of the class raises the event directly, but always callsOnFoo
.If you need to handle the event on
this
, it's usually both easier and faster to overrideOnFoo
.