Cyprich.com

Occasionally Relevant Insights from a Software Builder

By

How to Update .NET Windows Controls at Runtime

If you change the value of a control on Windows .NET form during runtime, it may not be updated with the changes. The following code should change the Text property of ToolStripStatusLabel, but it doesn’t work while its processing in the middle of its function. When its the last command in the function, it will change the label."

label_Folder.Text = "Converting documents to PDF.";

If additional code follows the label_Folder statement, it may not update the Text property. You can force the property to update with the Refresh method:

label_Folder.Text = "Converting documents to PDF.";
label_Folder.Refresh ();

The label will then be updated with the new content. If your using a ToolStripStatusLabel, you don’t have the option of using Refresh this way, i.e.

toolStripStatusLabel_ProcessingStatus.Text = "Status: 12 of 19 documents processed.";
toolStripStatusLabel_ProcessingStatus.Refresh ();

Instead, use this.Refresh () to force an update:

toolStripStatusLabel_ProcessingStatus.Text = "Status: 12 of 19 documents processed.";
this.Refresh ();

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.