Board index » cppbuilder » Label's caption doesn't show

Label's caption doesn't show

I want a message to appear on my form at the close of the run, something
like "Converting binary files to ASCII," along with a progress bar.  I
put a TLabel object and the progress bar onto a panel and set the panel
initially invisible.  During the execution, other TLabel components
having AutoSize = TRUE appear on the form, expanding to occupy space
that covers the invisible panel.  At the appointed time, I Show() the
panel.  It appears appropriately on top of (overwriting) the earlier
TLabel displays.  The progress bar it contains also appears.  But its
TLabel component does not display.  I have had similar trouble with
other TLabel components, even when directly placed on the underlying
form.  Sometime during execution another AutoSize-able TLabel component
expands to cover the location of the invisible TLabel (call it TLabel
*pWasInvisible).  Then the text of the hidden label remains invisible
after pWasInvisible->Show().  It's as if space on a form, once taken by
a TLabel component, is never freed for use by another TLabel component.
I have tried hiding the earlier label, and have also tried making its
caption small to get it to uncover *pWasInvisible.  Nothing works.  What
am I doing wrong?

Ron

 

Re:Label's caption doesn't show


This also drove me crazy once! The answer is that a TLabel does not descend
from TWinControl, and therefore does not have a window. Setting its
properties such as Caption does not reliably trigger the necessary
repainting (which must be done by the owner, not the component itself). I
worked around this situation by using the TStaticText (which I removed from
the Tab order).
HTH.

Frans

Re:Label's caption doesn't show


Frans:
        Many thanks for putting me on the right track!  One more thing I had to
do, being rather new at this, was to realize I must explicitly call the
Repaint() method.  Incidentally, I just checked and found Repaint() to
be a method in TControl, not TWinControl.  Maybe one can simply call
Repaint(), even with a TLabel component.  I haven't tried that yet.

Thanks for the key hint
Ron

Quote
Frans Hinlopen wrote:

> This also drove me crazy once! The answer is that a TLabel does not descend
> from TWinControl, and therefore does not have a window. Setting its
> properties such as Caption does not reliably trigger the necessary
> repainting (which must be done by the owner, not the component itself). I
> worked around this situation by using the TStaticText (which I removed from
> the Tab order).
> HTH.

> Frans

Other Threads