Strange problem drawing text in a dialog

R

Rinaldo

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
 
P

Peter Duniho

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
 
R

Rinaldo

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.
 
P

Peter Duniho

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top