Notification when my form is fully loaded in C# (.Net Compact Framework)?
14,528
Solution 1
What exaclty mean "fully loaded" ? Do you mean, the "Load" event was successfully proceeded?
You can do this:
public class MyForm : Form {
protected override void OnLoad( EventArgs e ) {
// the base method raises the load method
base.OnLoad( e );
// now are all events hooked to "Load" method proceeded => the form is loaded
this.OnLoadComplete( e );
}
// your "special" method to handle "load is complete" event
protected virtual void OnLoadComplete ( e ) { ... }
}
But if you mean "fully loaded" the "form is loaded AND shown" you need override the "OnPaint" method too.
public class MyForm : Form {
private bool isLoaded;
protected override void OnLoad( EventArgs e ) {
// the base method raises the load method
base.OnLoad( e );
// notify the "Load" method is complete
this.isLoaded = true;
}
protected override void OnPaint( PaintEventArgs e ) {
// the base method process the painting
base.OnPaint( e );
// this method can be theoretically called before the "Load" event is proceeded
// , therefore is required to check if "isLoaded == true"
if ( this.isLoaded ) {
// now are all events hooked to "Load" method proceeded => the form is loaded
this.OnLoadComplete( e );
}
}
// your "special" method to handle "load is complete" event
protected virtual void OnLoadComplete ( e ) { ... }
}
Solution 2
I think the OnLoad
event isn't really what you want, as it occurs before the form is displayed. You can use Application.Idle
with OnLoad
to make an OnLoaded
event though:
protected override void OnLoad(EventArgs args)
{
Application.Idle += new EventHandler(OnLoaded);
}
public void OnLoaded(object sender, EventArgs args)
{
Application.Idle -= new EventHandler(OnLoaded);
// rest of your code
}
Author by
Embedd_0913
Updated on June 05, 2022Comments
-
Embedd_0913 almost 2 years
I have a form in my application and I want to do some processing when my form has been
Fully loaded but I have no event or something which I can bind to when load is finished.
Does anyone has any idea, how can I do this?