OnLoad方法和Load事件之间的区别? [英] Difference between OnLoad method and Load event?
问题描述
OnLoad
方法和 Load
事件之间有什么区别?我正在开发WinForm控件.我应该注册 Load
事件还是重写 OnLoad
方法?每个人的优点和缺点是什么?
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?
推荐答案
我会优先考虑 OnLoad
,因此您可以节省CPU周期来调用事件处理程序.
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.
但记得调用基类的 OnLoad
方法,因为那是调用 Load
事件的地方.
But remember to call the base class' OnLoad
method, because that's where the Load
event invoked.
这篇关于OnLoad方法和Load事件之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!