开发者

About Load event of Windows Forms UserControl

Is there a guarantee that the Load event if an UserControl a开发者_开发知识库lways occurs after the InitializeComponent() method and the constructor have been completed?


No. The Load event runs right after the Handle is created. It is possible for the constructor to use a property of a control that requires the physical window to be created. That automatically triggers the CreateHandle() method, Load is next.

This is rare and usually a mistake. It tends to come to a good end, depending on what is being done in the event handler. Which ought to only ever do the kind of things that require the window. That's not common, anything else belongs in the constructor. The constructor however hasn't finished yet so you are working with a partially initialized object. Accidents are possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜