Check if the form is uploaded

I have two forms.

  • One of them is the main form (call MainForm)
  • another to display some warning (call it dialogForm)

. dialogForm has a shortcut in it. When I click the button in MainForm, a dialog box opens. But the shortcut in the dialog format is empty. In fact, he does not have time to download. I want to check if the dialogForm function is fully loaded and then proccess in MainForm. For instance:

dialogForm tempFrm = new dialogForm(); tempFrm.Show(); // I want to wait till the dialogForm is fully loaded. Then continue to "while" loop. while(..) { ... } 
+4
source share
4 answers

you can try the following

 private bool Is_Form_Loaded_Already(string FormName) { foreach (Form form_loaded in Application.OpenForms) { if (form_loaded.Text.IndexOf(FormName) >= 0) { return true; } } return false; } 

you can also look at this

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

+2
source

So you need to use the Shown event forms:

 tempFrm.Shown += (s, e) => { while(..) { } } 

But you will have another problem. He is going to block the flow. You need to run this while in another thread using BackgroundWorker or Thread .

+1
source

Why not create a boolean and a method to access it.

 private bool Ready = false; public ConstructorMethod() { // Constructor code etc. Ready = true; } public bool isReady() { return Ready; } 
0
source

Your time (...) blocks the user interface thread, so the child form will never receive messages and will not be loaded.

To achieve the goal, you must subscribe to the Load event and continue your code in the handler.

 void Click() { var tempFrm = new dialogForm(); tempFrm.Load += frmLoad; tempFrm.Show(); } void frmLoad(object s, EventArgs ea) { // form loaded continue your code here! } 
0
source

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


All Articles