469,950 Members | 2,480 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Strange problem drawing text in a dialog

Hi,

I have a label on my dialogbox who has to change text while running. This is
what I do:

lblBackup.Text = "Bezig met de backup naar " + F1.FTPserver;

but the text does'nt appear, only if I draw (call) a messagebox, then the
text appears. What can it be? I had made a total new one, but did'nt help.

Rinaldo

Nov 5 '07 #1
3 1791
On 2007-11-05 06:46:03 -0800, "Rinaldo"
<zw*************@hotmail.com.nospamsaid:
I have a label on my dialogbox who has to change text while running.
This is what I do:

lblBackup.Text = "Bezig met de backup naar " + F1.FTPserver;

but the text does'nt appear, only if I draw (call) a messagebox, then
the text appears. What can it be? I had made a total new one, but
did'nt help.
If I had to guess (and I do, because you didn't post nearly enough code
to illustrate what you're actually doing), I'd guess that you are in
some sort of processing loop in which you change the Text property of
the Label and that processing loop is in the main UI thread.

If that's the case, then until the processing loop has completed and
whatever UI method started the processing loop returns, nothing in your
UI will be able to redraw itself, including the Label that you've
changed.

If you have a lengthy processing to do and you have a need for the UI
to remain responsive (including redrawing when you update it), then you
need to put the processing into a different thread so that the UI can
update itself when necessary.

The BackgroundWorker class is ideal for simple examples of this sort of
situation. You can use it to run your processing, and from the
processing code use the Control.Invoke() method to execute code that
will update the UI. Then the UI changes will actually be visible to
the user while the processing goes on.

Pete

Nov 5 '07 #2
Hi pete,

The strange thing was that it suddenly stopped. It was because it did'nt
redraw the dialog, but a this.Refresh() worked. I do'nt know why it stopped
to work.

Thanx for your excelent explanation, but I have just yet another bunch of
questions, I am a beginner. I formally programmed C, but that's 20 years
ago.

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comschreef in bericht
news:2007110509155650073-NpOeStPeAdM@NnOwSlPiAnMkcom...
On 2007-11-05 06:46:03 -0800, "Rinaldo"
<zw*************@hotmail.com.nospamsaid:
>I have a label on my dialogbox who has to change text while running. This
is what I do:

lblBackup.Text = "Bezig met de backup naar " + F1.FTPserver;

but the text does'nt appear, only if I draw (call) a messagebox, then the
text appears. What can it be? I had made a total new one, but did'nt
help.

If I had to guess (and I do, because you didn't post nearly enough code to
illustrate what you're actually doing), I'd guess that you are in some
sort of processing loop in which you change the Text property of the Label
and that processing loop is in the main UI thread.

If that's the case, then until the processing loop has completed and
whatever UI method started the processing loop returns, nothing in your UI
will be able to redraw itself, including the Label that you've changed.

If you have a lengthy processing to do and you have a need for the UI to
remain responsive (including redrawing when you update it), then you need
to put the processing into a different thread so that the UI can update
itself when necessary.

The BackgroundWorker class is ideal for simple examples of this sort of
situation. You can use it to run your processing, and from the processing
code use the Control.Invoke() method to execute code that will update the
UI. Then the UI changes will actually be visible to the user while the
processing goes on.

Pete

Nov 5 '07 #3
On 2007-11-05 10:35:10 -0800, "Rinaldo"
<zw*************@hotmail.com.nospamsaid:
The strange thing was that it suddenly stopped. It was because it
did'nt redraw the dialog, but a this.Refresh() worked. I do'nt know why
it stopped to work.
Don't use Refresh(). It's a hack. If calling Refresh() causes the
update to happen, then it's almost certain that the problem is exactly
as I described and should be solved in the way I describe, rather than
calling Refresh() or related methods (e.g. don't call Control.Update()
or Application.DoEvents() either).
Thanx for your excelent explanation, but I have just yet another bunch
of questions, I am a beginner. I formally programmed C, but that's 20
years ago.
Well, that's what the newsgroup is for. To answer questions. :) So
fire away...

That said, there are numbers of threads already discussing the
fundamental concepts raised here: BackgroundWorker and
Control.Invoke(). Google Groups will help you find those. It's
entirely possible that any question you might have has already been
asked and answered here, so you should check the archives before
posting new questions.

Pete

Nov 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by chau_fai | last post: by
reply views Thread by Christof Nordiek | last post: by
2 posts views Thread by escher4096 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.