Form.Show() not displaying Label. ShowDialog does.

  • Thread starter Thread starter AlexGray
  • Start date Start date
A

AlexGray

Hi,

I created a blank Form with one Label, and the Label's text says
"Loading... Please wait.". I display this form in Main() with Show()
while i do some lengthy initialization stuff (ie loading files), but
the Label appears transparent! I can see through to my desktop where
the Label control is. But, if i display this form with ShowDialog(),
it displays the label fine. Am I missing something here?

Here is the code:
private static void Main()
{
LoadingForm lf = new LoadingForm();
lf.Show(); // The label doesn't get displayed!

// Do length, time consuming stuff ...

lf.Close();
}

But if i do this, the Label gets displayed fine:
private static void Main()
{
LoadingForm lf = new LoadingForm();
lf.ShowDialog(); // The label gets displayed fine!

// Do length, time consuming stuff ...


}

any ideas why this could be happening?

-alex-
 
I'm not using Application.Run anywhere.
My "application" is just a ShowDialog() window. When that window is
closed, Main() terminates and the application closes.

ie ( I can reproduce it like this. I'm use Thread.Sleep to simulate a
bunch of loading time. I also noticed that both in my app and in this
demo below i can't move the "Loading" window. It's frozen and says
"Not Responding" if i try to click on it.):
using System.Threading;
public class InitializeGame
{
private static void Main()
{
Form1 ld = new Form1();
ld.Show();
Thread.Sleep(5000);
ld.Close();
}
}

I think you're getting to the bottom of this...
 
Ah. I figured it out. I ended up creating a new thread that launches
my "Loading... Please wait" form.
In the Loading form i added this code:
public new void Show()
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}

public void ThreadProc()
{
Application.Run (new Loading() );
}
If you have any questions, feel free to ask :)
-alex-
 
Back
Top