Check if the form is loaded

15,634

Solution 1

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

private bool Ready = false;

public ConstructorMethod()
{
    // Constructor code etc.
    Ready = true;
}

public bool isReady()
{
    return Ready;
}

Solution 2

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 in this

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

Solution 3

So you need to consume the forms Shown event:

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

But you're going to have another problem. It's going to block the thread. You need to run this while loop on another thread by leveraging a BackgroundWorker or Thread.

Share:
15,634

Related videos on Youtube

MilesDyson
Author by

MilesDyson

Working on some super-weird-secret-robot-stuff for Cyberdyne...

Updated on June 04, 2022

Comments

  • MilesDyson
    MilesDyson almost 2 years

    I have two forms.

    • One of them is the main form (let's call it MainForm)
    • the other one is for showing some warning (let's call it dialogForm)

    . dialogForm has a label in it. When i click a button in MainForm, dialogForm opens. But label in dialogForm is blank. It doesn't have time to load actually. I want to check if the dialogForm fully loaded then proccess can continue in MainForm. For example:

    dialogForm tempFrm = new dialogForm();
    tempFrm.Show(); // I want to wait till the dialogForm is fully loaded. Then continue to "while" loop.
    while(..)
    {
    ...
    }
    
    • user1703401
      user1703401 over 10 years
      Call tempFrm.Update(). Using long while loops in UI code is fundamentally the wrong thing to do. Don't do it.
    • Viacheslav Smityukh
      Viacheslav Smityukh over 10 years
      What is a goal that are you hunting for?
    • MilesDyson
      MilesDyson over 10 years
      @Hans your tempFrm.Update() suggestion solved the problem. By the way there wasn't a while loop in orginal code. It was just an example :) Thanks for the answer.
    • user1703401
      user1703401 over 10 years
      You can't get good answers if you post fake code :(
    • MilesDyson
      MilesDyson about 10 years
      @HansPassant If you post your "tempFrm.Update()" solution as an answer, I can accept it. This question has almost a 1000 views. And people can miss your answer here.
  • Elikill58
    Elikill58 over 2 years
    Before the edit, it was better. Here, can you edit to more explain more why and how this should fix it ?