Hi,
I've noticed that when loading styles through StyleManager.Load, the Load event on my usercontrols happens earlier in some scenarios. I still haven't identified which scenario makes this happen (as I have different UserControls and some of them work as they work without styles and others more complex raise the event before)
The event seems to be raised exactly when the ResumeLayout(false) method is called in the topmost Container in the user control.
Is this expected behavior? What could be the reasons for this to happen?
If I remove the StyleManager.Load declaration from my application then everything works as normal.
Edit: This only seems to happen with the Office2007 style?
Thanks,
Sebastian
Hello,
An event in C# is a way for a class to provide notifications to clients of that class when some interesting thing happens to an object. The most familiar use for events is in graphical user interfaces; typically, the classes that represent controls in the interface have events that are notified when the user does something to the control (for example, click a button).
Load Event of the user control occurs before the control becomes visible for the first time.
The Load event occurs when the handle for the UserControl is created. In some circumstances, this can cause the Load event to occur more than one time. For example, the Load event occurs when the UserControl is loaded, and again if the handle is recreated. (One way that a handle is recreated is by calling the RecreateHandle method.) To account for the Load event occurring more than one time, you should put any one time initialization code in the UserControl constructor instead of a Load event handler. In addition, you should not add data bindings to the UserControl in a Load event handler.
Calling the ResumeLayout method forces an immediate layout if there are any pending layout requests. So if you use AppStylist to style your application ResumeLAyout could cause firing of Load event, if the control is not visible, in order to redraw the control.
Please let me know if you have any further questions
Hi Hristo,
Thanks for the answer, it got to me a little bit late so is not of much help really now. But what you say is what I think was happening, we moved all the code we had in Load to a better place.
Cheers