Repost: label not showing up in form when calling form from other form using .Show()

S

Steve Sargent

Hi:

I'm trying to setup a simple message box that displays a message (like
"Exiting Applicaton....). It's a simple form with only one label on
it, displayed in the center.

The label's text is set after initializecomponents is called from the
form's constructor.

I'm trying to use this in other forms. Right now, in the load handler
for another form, I have a warning message. If the user chooses no,
I'd like to have the display message show on the screen for a couple
of seconds before exiting app.

I create an instance of the message form from within the other form's
load handler and call Show().

The form displays on the screen, but where the label should be, is
only a white rectangular area, with no text at all.

Is there some extra precautions needed when calling other forms from
within your form application?

Any advice and/or help is appreciated.

Thanks
 
H

Herfried K. Wagner [MVP]

* I_hate_spammers@spammers_suck.com (Steve Sargent) scripsit:
I'm trying to setup a simple message box that displays a message (like
"Exiting Applicaton....). It's a simple form with only one label on
it, displayed in the center.

The label's text is set after initializecomponents is called from the
form's constructor.

I'm trying to use this in other forms. Right now, in the load handler
for another form, I have a warning message. If the user chooses no,
I'd like to have the display message show on the screen for a couple
of seconds before exiting app.

I create an instance of the message form from within the other form's
load handler and call Show().

The form displays on the screen, but where the label should be, is
only a white rectangular area, with no text at all.

Is there some extra precautions needed when calling other forms from
within your form application?

Can you upload a minimal project that can be used to repro this behavior
somewhere?
 
S

Steve Sargent

Sure thing..

* I_hate_spammers@spammers_suck.com (Steve Sargent) scripsit:

Can you upload a minimal project that can be used to repro this behavior
somewhere?
 
S

Saurabh

I think the problem is in your Thread.sleep(10000) call. It makes the thread
to sleep. since your message window is on the same thread, it doesn't paint
itself.

I altered some of your code to simulate the same behaviour by adding a timer
to the class. instantiating the timer in the constructor, starting the
timer when the dialog is shown and disposing the dialog when the time
ticks....

Mind you, this leaves the main form in interactive mode and the user can
click the "Click Me" button again and again.... you can handle it by either
disabling it or not creating a new message is one is already shown.

HTH,

--Saurabh

news:[email protected]...
 
H

Herfried K. Wagner [MVP]

* I_hate_spammers@spammers_suck.com (Steve Sargent) scripsit:
[...]

The behavior is caused by this line:

\\\
Thread.Sleep(10000);
///

Show the form by calling its 'Show' or 'ShowDialog' method and use a
timer ('System.Windows.Forms.Timer') to close the form by calling its
'Close' method. The code above will block the whole UI thread.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top