Board index » cppbuilder » Creating a button at runtime on a runtime form

Creating a button at runtime on a runtime form

I am having trouble creating a TButton on a TForm, both created at runtime.
The TForm shows up fine, but the button does not.  I have declared
__fastcall TButton *ms1; in the header.  My create is
ms1=new TButton(parent);   and I have assigned a parent to the button and
also width and height and caption.
Is there something I'm missing?  Rohan
 

Re:Creating a button at runtime on a runtime form


You *have* assigned the Parent property??

    ms1->Parent = ControlToUseAsParent;

Gambit

"Eugene J. Champagne" <ti...@earthlink.net> wrote in message
news:3b1ad98e_2@dnews...

Quote
> I am having trouble creating a TButton on a TForm, both created at
runtime.
> The TForm shows up fine, but the button does not.  I have declared
> __fastcall TButton *ms1; in the header.  My create is
> ms1=new TButton(parent);   and I have assigned a parent to the button and
> also width and height and caption.

Re:Creating a button at runtime on a runtime form


Yes, I have assigned the parent property.  The button still doesn't show up
on the form.
Rohan

Quote
"Remy Lebeau" <gambi...@gte.net> wrote in message news:3b1afd4e_1@dnews...
> You *have* assigned the Parent property??

>     ms1->Parent = ControlToUseAsParent;

> Gambit

> "Eugene J. Champagne" <ti...@earthlink.net> wrote in message
> news:3b1ad98e_2@dnews...
> > I am having trouble creating a TButton on a TForm, both created at
> runtime.
> > The TForm shows up fine, but the button does not.  I have declared
> > __fastcall TButton *ms1; in the header.  My create is
> > ms1=new TButton(parent);   and I have assigned a parent to the button
and
> > also width and height and caption.

Re:Creating a button at runtime on a runtime form


What exactly does your code look like?

Gambit

Eugene J. Champagne <ti...@earthlink.net> wrote in message
news:3b1b7103_2@dnews...

Quote
> Yes, I have assigned the parent property.  The button still doesn't show
up
> on the form.

Re:Creating a button at runtime on a runtime form


On Mon, 4 Jun 2001 09:30:38 -0700, "Remy Lebeau" <gambi...@gte.net>
wrote:

ms1 is TButton, sean2 is TForm, both created at runtime

ms1=new TButton(sean2);
ms1->parent=sean2;
ms1->Enabled=false;
ms1->Visible=false;
ms1->Left=5;
ms1->Top=sean2->Top + sean2->Height -30;
ms1->Width=100;
ms1->Height=25;
ms1->Caption="Send to Fill Color";
ms1->Visible=true;
ms1->Enabled=true;
ms1->Show();

Quote
>What exactly does your code look like?

>Gambit

>Eugene J. Champagne <ti...@earthlink.net> wrote in message
>news:3b1b7103_2@dnews...
>> Yes, I have assigned the parent property.  The button still doesn't show
>up
>> on the form.

Re:Creating a button at runtime on a runtime form


Pardon me for jumping in, but I think your problem is in the following
line

Quote
> ms1->Top=sean2->Top + sean2->Height -30;

Don't forget that your form's Top property is the top of the form with
respect to the screen or desktop, ie in screen co-ordinates, and your
button's position is in client co-ordinates.

For example, if your sean2 form is placed at 200 pixels from the top of
the screen/desktop, and the height of sean2 is 100 pixels, then your ms1
button will be 270 (200 + 100 - 30) pixels from the top of your form's
client rect.  In other words, it will not be visible.

Try using something like:

    ms1->Top = sean2->ClientHeight - 30 ;

Or, even better, use the SetBounds function, which sets all of a
controls dimensions in one go:

    ms1->SetBounds( 5 , sean2->ClientHeight - 30 , 100 , 25 ) ;

--
Andrew

Quote
<ti...@earthlink.net> wrote in message

news:3b1bf611.6545171@newsgroups.borland.com...
[snip]
Quote
> >> Yes, I have assigned the parent property.  The button still doesn't
show
> >up
> >> on the form.

Re:Creating a button at runtime on a runtime form


On Mon, 4 Jun 2001 23:28:43 +0100, "Andrew"

Quote
<andrew.r.t.no.spam.ple...@btinternet.com> wrote:

Thank you Andrew, you were right, it works now, plus putting button
creation code in main unit instead of OnActivate of sean2.  Rohan

PS  I must be getting potty in my old age :)

Quote
>Pardon me for jumping in, but I think your problem is in the following
>line

>> ms1->Top=sean2->Top + sean2->Height -30;

>Don't forget that your form's Top property is the top of the form with
>respect to the screen or desktop, ie in screen co-ordinates, and your
>button's position is in client co-ordinates.

>For example, if your sean2 form is placed at 200 pixels from the top of
>the screen/desktop, and the height of sean2 is 100 pixels, then your ms1
>button will be 270 (200 + 100 - 30) pixels from the top of your form's
>client rect.  In other words, it will not be visible.

>Try using something like:

>    ms1->Top = sean2->ClientHeight - 30 ;

>Or, even better, use the SetBounds function, which sets all of a
>controls dimensions in one go:

>    ms1->SetBounds( 5 , sean2->ClientHeight - 30 , 100 , 25 ) ;

>--
>Andrew

><ti...@earthlink.net> wrote in message
>news:3b1bf611.6545171@newsgroups.borland.com...
>[snip]
>> >> Yes, I have assigned the parent property.  The button still doesn't
>show
>> >up
>> >> on the form.

Other Threads