views:

28

answers:

1

Is there a guarantee that the Load event if an UserControl always occurs after the InitializeComponent() method and the constructor have been completed?

+1  A: 

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.

Hans Passant