Search code examples
c#.netcompact-framework

Notification when my form is fully loaded in C# (.Net Compact Framework)?


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?


Solution

  • 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 ) { ... }
    }