One of our users has sent in a log for our .NET Winforms application that indicates that the Activated
event is occurring before the Load
event. I didn't think this was possible and have coded with the assumption that Load
would always happen before Activated
.
Has anyone else observed Activated
occurring before Load
?
If so, why and is there any way to make sure it doesn't happen?
Activated comes before Load. If you want to write some code that should be executed after Load then you can Use Shown Method.
Please find below the sequence :
EDIT : Please check this very interesting answer on SO which explains WinForms Load vs. Shown events
From Order of Events in Windows Forms at MSDN:
Are you using a MessageBox in any of your startup events? This can cause the events to appear to trigger out of order because of the way the Windows Forms Message Loop handles dialog windows.
Even though it goes against Microsoft's documentation, this can happen sometimes when you access a loading form's public variable or function from outside the form. If necessary, you can set a flag in the shown event and use it to exit the activated handler before the form has loaded.