Reputation: 2537
Good day,
I have a couple of methods that take long in my forms code. I would like to display a message (using a label
on another form) to inform the user about what is going on, so they don't assume program is unresponsive.
I don't want to use MessageBox.Show()
, because I would like to have an object that I can change the text of, and dispose when needed, without user being able to close it.
so far I have somthing like this: in my main form:
private void Foo()
{
Form2 infoPopup = new Form2();
infoPopup.setText("running function1");
infoPopup.Show();
slowFunction1();
infoPopup.setText("running function2");
slowFunction2();
infoPopup.Dispose();
}
as you might guess, in Form 2 I have a function like this:
private void setText(string message)
{
this.label1.Text=message;
}
Unfortunately this solution only partially works. I do get the form2
popup message but the content of the label in form2
do not change.
Thanks
Upvotes: 0
Views: 513
Reputation: 67345
When your application is busy, redrawing controls is not a priority. So unless your code is running in a worker thread, the UI won't update reliable.
You can force an update though. Controls and forms all have a Update()
method. It forces the object to redraw itself.
Depending on your particular case, you might also want to research the Invalidate()
and Refresh()
methods.
Upvotes: 1