Board index » cppbuilder » Create Labels at runtime

Create Labels at runtime

Hi,
How can I create labels at runtime? My application has a page control with many tabsheets, and as the user selects a tabsheet I want to place labels on the selected tabsheet.
I have used the following code in the OnShow event for the tabsheet:
TLabel* lab = TLabel(this);
lab->Caption = "Some Text";
lab->Visible = true;

The code compiles and runs, but the labels do not appear!
Can anyone help?
Thanks - Cliff.

 

Re:Create Labels at runtime


Everything is ok, you just miss one thing. You need to set label's parent:
lab->Parent = this;

or, if you want the label on TabSheet:
lab->Parent = TabSheet1;

===== ___                        = Milan Babuskov, Support Engineer
==== /     /  /   __   ___  _/_ == EUnet - YUnet International

Quote
> TLabel* lab = TLabel(this);
> lab->Caption = "Some Text";
> lab->Visible = true;

Re:Create Labels at runtime


You need to set the Parent property to the desired TabSheet.  Also keep in
mind that 'this' will point to the form itself, not the TabSheet (which is
fine, if you want the form, not the TabSheet, managing the memory)

Gambit

Quote
"Cliff" <cmcda...@aei.ca> wrote in message news:3bbdb6a6$1_1@dnews...
> I have used the following code in the OnShow event for the tabsheet:
> TLabel* lab = TLabel(this);
> lab->Caption = "Some Text";
> lab->Visible = true;

> The code compiles and runs, but the labels do not appear!

Re:Create Labels at runtime


Try this,

TLabel* lab = new TLabel(this);
lab->Parent = TabSheet ;
lab->Caption = "Some Text";
lab->Visible = true;

Stewart

Quote
"Cliff" <cmcda...@aei.ca> wrote in message news:3bbdb6a6$1_1@dnews...

> Hi,
> How can I create labels at runtime? My application has a page control with

many tabsheets, and as the user selects a tabsheet I want to place labels on
the selected tabsheet.
Quote
> I have used the following code in the OnShow event for the tabsheet:
> TLabel* lab = TLabel(this);
> lab->Caption = "Some Text";
> lab->Visible = true;

> The code compiles and runs, but the labels do not appear!
> Can anyone help?
> Thanks - Cliff.

Re:Create Labels at runtime


Quote
"Cliff" <cmcda...@aei.ca> wrote:

>Hi,
>How can I create labels at runtime? My application has a page control with many tabsheets, and as the user selects a tabsheet I want to place labels on the selected tabsheet.
>I have used the following code in the OnShow event for the tabsheet:
>TLabel* lab = TLabel(this);
>lab->Caption = "Some Text";
>lab->Visible = true;

>The code compiles and runs, but the labels do not appear!
>Can anyone help?
>Thanks - Cliff.

Thanks to all respondents!
Cliff

Other Threads