Windows Develop Bookmark and Share   
 index > Windows Forms General > toolStripStatusLabel.Text doesn't update?
 

toolStripStatusLabel.Text doesn't update?

I am able to set the toolStripStatusLabel.Text before showing the Form, butafter the Form is shown then changing the status is not possible.
I do have tried Application.DoEvents() but didn't help.
Am using .Net/VS2005/C#.

This works:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
gui =
new GUIForm();
gui.StatusLabel = "Ready";
Application.Run(gui);

This doesn't works:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
gui =
new GUIForm();
Application.Run(gui);
gui.StatusLabel =
"Ready";
Application.DoEvents();

VValdo  Sunday, February 26, 2006 6:47 PM
Application.Run starts pumping the message loop on your UI thread. It does notreturn until your form closes. So the statement that changes the StatusLabel on your form is not executing until after the form is closed.
CommonGenius.com  Monday, February 27, 2006 12:31 AM

Ok, I think I understand it.

But how can I update the Form?

Can you give me some example code?

VValdo  Monday, February 27, 2006 9:59 AM
At what point do you want to update the form? If you want to update it in response to a particular event, then put your statement in a handler for that event.
CommonGenius.com  Monday, February 27, 2006 2:58 PM

The form should be updated byexternal code (not a buttonclick-event or so).

E.g. After the Form is shown, then (automatically)a connection is madeto an external server, this should update the status-bar with"Connecting..." and then "Connected".

Then data isreceiving from the server, the timestamp should be put in the statusbar "Last received at 2006-02-27 17:05".

Hopes this helps...

VValdo  Monday, February 27, 2006 4:05 PM
I am confused. If you know when you need to update the text of the status bar, what do you need help with? In the method where you are receiving data, update the timestamp.
CommonGenius.com  Monday, February 27, 2006 4:22 PM

The problem is that the ToolStripStatusLabel bar doesn't change because it is in a separate thread (if I understand your previous answer correctly).

My code is as follows:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
gui =
new GUIForm();
gui.StatusLabel = "Ready";
Application.Run(gui);
methodToConnectToServer(http://127.0.0.1);
gui.StatusLabel = "Connecting... Please wait...";
methodToReceiveData(http://127.0.0.1);
gui.StatusLabel = "Received data: " + Now();

The statuslabel display "Ready" and doesn't change.

VValdo  Monday, February 27, 2006 5:45 PM
Application.Run does not start a separate UI thread, it IS your UI thread. It does not return until your form is closed.The code you have is not multi-threaded; it is all in one thread. So the code you have after Application.Run is not executing until your form is closed. That is why you dont see your status label changing. Check out this article for more information on asynchronous processing using multi-threading: http://www.codeproject.com/dotnet/multithread.asp
CommonGenius.com  Monday, February 27, 2006 7:12 PM
Try this:
this.toolStripStatusLabel.Text = "success!";
this.Refresh();

  • Proposed As Answer byJarno Burger Saturday, October 10, 2009 9:14 PM
  •  
Kuti  Tuesday, March 14, 2006 4:28 PM

I had the same problem.

I just wanted to say thanks to kuti for the last post because it helped.

Coot  Monday, December 18, 2006 2:10 PM
Lots of thanks Kuti...
Kronosizm  Wednesday, May 21, 2008 2:11 PM

You can use google to search for other answers

Custom Search

More Threads

• How to determine File Type?
• How can I capture Keystrokes and analyze the content in RichTextBox (VS 2003)?
• (URGENT) Proxy Authentication required for Windows Application
• Drag-and-drop in partially trusted environment
• How to programatically scroll down the panel to a child control?
• Anyone know why my pretty icons look stupid on toolbars? :-)
• Control Development - Creating a scrollable control that contains line numbers and text in a virtual fashion
• Vista Taskbar Upgrade
• How to get the value of View Ruler in Microsoft Word in c# program?
• connecting PDA to a laptop via wireless network