Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WinForms label will display, but not show text

I'm designing a GUI and I have a label which I use effectively as a 'please wait' message after I invoke an action that tends to take a while. The label's text is static, I have set it in the properties in VS2010 for the label control.

When I hit that action on the form, I .Show() the control which is normally hidden until the time consuming process completes, then .Hide() it. When it hits the .Show() the label pops up (I know this because I have the BorderStyle set to Fixed3D so I see the border of the label show up) but there is no text in it whatsoever. I have tried setting the label to autosize and not to no avail, my text is set to black on gray, so no invisible ink, everything is visible, font is set. Code executes as I want it to throughout, theres just no text in the label. I'm at a loss.

Any ideas?

like image 378
Josh Bibb Avatar asked Oct 25 '12 21:10

Josh Bibb


3 Answers

If the time consuming process is occurring on the same thread, then it could be a refresh/redraw issue (where the processor is too busy to handle UI requests). Try either refreshing the window before starting the long running process or, more appropriately, putting the time consuming process in a BackgroundWorker.

like image 56
JDB Avatar answered Nov 04 '22 01:11

JDB


If the time-consuming process is not executing in a background thread, then your UI isn't updating because no message processing is taking place. Controls redraw themselves in WM_Paint messages.

Try calling Refresh on the control or on its window-handle parent (the form) after changing its state, before diving into the long process.

Or, move the long-running process into a background thread (see .NET 4.0 Task) to free up the UI thread.

like image 44
dthorpe Avatar answered Nov 04 '22 00:11

dthorpe


Maybe I'm missing something, but why don't you just set label.Visible?

like image 44
Michael Sallmen Avatar answered Nov 04 '22 02:11

Michael Sallmen