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 was

Fully loaded, but I do not have an event or something that I can bind when the download is complete.

Does anyone know how I can do this?

+1
source share
5 answers

What does the expression β€œfully loaded” mean? Do you mean that the "Download" event was successfully continued?

You can do it:

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 loading and showing", you also need to override the "OnPaint" method.

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

I think the OnLoad event is not really what you want, as it happens before the form is displayed. You can use Application.Idle with OnLoad to make the OnLoaded event:

 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 } 
+4
source

My approach is similar to the accepted answer from TcK. The problem I ran into was that I had an event handler for a group of controls that responded to VisibleChanged using an event handler that controls the controls inside the Panel. The problem was (of course) that visibility changed when the form was first loaded, but after the .Load () event.

I created and set the bool value for the form:

 private bool formShown = false; 

and then added the following line to the form Form_Load ()

 this.Paint += (s, args) => { formShown = true; }; 

with the first line of my VisibleChanged () event handler:

 if(!formShown) { return; } 

Short and functional.

0
source

You can use the Load event of the form. In the constructor of your form write the following line

 this.Load += new System.EventHandler(this.Form1_Load); 

and then write the following method in which you can do some things.

 void Form1_Load(object sender, EventArgs e) { // do some stuff here. } 
-one
source

Source: https://habr.com/ru/post/1494725/


All Articles