Board index » cppbuilder » Re: Design time positioning of child controls

Re: Design time positioning of child controls


2004-06-25 05:43:53 PM
cppbuilder38
"Paw Suddergaard" < XXXX@XXXXX.COM >wrote in message news: XXXX@XXXXX.COM ...
Quote
This method gives me the same result.

In designtime, it set the buttons position just right! But in runtime the
button is set at default position... ????

Please help!
I didn't initialize the button's position in previous code.
Here is what it should look like:
__fastcall TControlX::TControlX(TComponent* Owner)
: TCustomControl( Owner )
{
Width = 69;
Height = 69;
BevelKind = bkTile;
Button1 = new TSpeedButton(this);
Button1->Parent = this;
Button1->Caption = "...";
Button1->SetBounds(23,23,19,19); //Initialize position
}
I also declared TControlX::SetBounds in the protected section,
it should be in public section, although that has nothing to
do with position problem.
Todd
 
 

Re:Re: Design time positioning of child controls

Still the same! :o(
******* Code: ********
class PACKAGE TBox : public TWinControl
{
private:
TComboBox *FComboBox;
TBitBtn *FBitBtn;
..............
protected:
public:
__fastcall TBox(TComponent* Owner);
__fastcall virtual ~TBox();
virtual void __fastcall SetBounds(int ALeft, int ATop, int AWidth, int
AHeight);
............
__published:
...........
};
//--------------------------------------------------------------------------
-
#endif
__fastcall TBox::TBox(TComponent* Owner)
: TWinControl(Owner)
{
FComboBox = new TComboBox(this);
FBitBtn = new TBitBtn(this);
this->Width = 185;
this->Height = 21;
Parent = (TWinControl*)Owner;
FComboBox->Parent = this;
FComboBox->Height = 21;
FComboBox->Width = this->Width;
FComboBox->Top = this->Top;
FComboBox->Left = this->Left;
FComboBox->Align = alTop;
FBitBtn->Parent = this;
FBitBtn->SetBounds((FComboBox->Left+FComboBox->Width)-(FBitBtn->Width+2),FCo
mboBox->Top+2,17,18);
}
//--------------------------------------------------------------------------
-
__fastcall TBox::~TBox()
{
//Clear Memory...
}
//--------------------------------------------------------------------------
-
void __fastcall TBox::SetBounds(int ALeft, int ATop, int AWidth, int
AHeight)
{
TWinControl::SetBounds(ALeft,ATop,AWidth,AHeight);
if(FBitBtn){
FBitBtn->SetBounds((FComboBox->Left+FComboBox->Width)-(FBitBtn->Width+2),FCo
mboBox->Top+2,17,18);
}
}
//--------------------------------------------------------------------------
-
"Todd Brylski" < XXXX@XXXXX.COM >wrote in message
Quote
"Paw Suddergaard" < XXXX@XXXXX.COM >wrote in message
>This method gives me the same result.
>
>In designtime, it set the buttons position just right! But in runtime
the
>button is set at default position... ????
>
>Please help!

I didn't initialize the button's position in previous code.
Here is what it should look like:

__fastcall TControlX::TControlX(TComponent* Owner)
: TCustomControl( Owner )
{
Width = 69;
Height = 69;
BevelKind = bkTile;

Button1 = new TSpeedButton(this);
Button1->Parent = this;
Button1->Caption = "...";
Button1->SetBounds(23,23,19,19); //Initialize position
}

I also declared TControlX::SetBounds in the protected section,
it should be in public section, although that has nothing to
do with position problem.

Todd


 

Re:Re: Design time positioning of child controls

"Paw Suddergaard" < XXXX@XXXXX.COM >wrote in message
Quote
this->Width = 185;
this->Height = 21;
Use SetBounds() instead:
this->SetBounds(Left, Top, 185, 21);
Also, don't call SetBounds() until after you have instantiated the ComboBox
and BitBtn. That way, you can have a single place where the BitBtn is
positioned, instead of calling FBitBtn->SetBounds() with the same values in
two different places.
Quote
Parent = (TWinControl*)Owner;
Why are you doing that? You should not be.
Quote
FComboBox->Height = 21;
FComboBox->Width = this->Width;
FComboBox->Top = this->Top;
FComboBox->Left = this->Left;
By using the Align property, you don't need to set the Left, Top, and Width
properties at all (which, btw, you are not setting the Left and Top
properties correctly anyway). They are set automatically whenever the main
component is resized.
Use this code instead:
__fastcall TBox::TBox(TComponent* Owner)
: TWinControl(Owner)
{
FComboBox = new TComboBox(this);
FComboBox->Parent = this;
FComboBox->Align = alTop;
FBitBtn = new TBitBtn(this);
FBitBtn->Parent = this;
SetBounds(Left, Top, 185, 21);
}
void __fastcall TBox::SetBounds(int ALeft, int ATop, int AWidth, int
AHeight)
{
TWinControl::SetBounds(ALeft,ATop,AWidth,AHeight);
if( (FComboBox) && (FBitBtn) )
{
FComboBox->Height = AHeight;
FBitBtn->SetBounds(AWidth-19, 2, 17, AHeight-4);
}
}
Quote
FBitBtn->SetBounds((FComboBox->Left+FComboBox->Width)
-(FBitBtn->Width+2),FComboBox->Top+2,17,18);
It looks like you are trying to place the button on top of the ComboBox, is
that correct? If so, why? Are you trying to custom-draw the combobox's own
button, by chance?
Gambit
 

{smallsort}

Re:Re: Design time positioning of child controls

Hi! Thanks for the great help!
Quote
>Parent = (TWinControl*)Owner;

Why are you doing that? You should not be.
I am still very newbie to writing components, so thats why i am a little
confused. But it works now! Great!
Quote
It looks like you are trying to place the button on top of the ComboBox,
is
that correct? If so, why? Are you trying to custom-draw the combobox's
own
button, by chance?
Yes I am trying to create a Combobox that i am custom-drawing.
Again Thanks!
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Paw Suddergaard" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>this->Width = 185;
>this->Height = 21;

Use SetBounds() instead:

this->SetBounds(Left, Top, 185, 21);

Also, don't call SetBounds() until after you have instantiated the
ComboBox
and BitBtn. That way, you can have a single place where the BitBtn is
positioned, instead of calling FBitBtn->SetBounds() with the same values
in
two different places.

>Parent = (TWinControl*)Owner;

Why are you doing that? You should not be.

>FComboBox->Height = 21;
>FComboBox->Width = this->Width;
>FComboBox->Top = this->Top;
>FComboBox->Left = this->Left;

By using the Align property, you don't need to set the Left, Top, and
Width
properties at all (which, btw, you are not setting the Left and Top
properties correctly anyway). They are set automatically whenever the
main
component is resized.

Use this code instead:

__fastcall TBox::TBox(TComponent* Owner)
: TWinControl(Owner)
{
FComboBox = new TComboBox(this);
FComboBox->Parent = this;
FComboBox->Align = alTop;

FBitBtn = new TBitBtn(this);
FBitBtn->Parent = this;

SetBounds(Left, Top, 185, 21);
}

void __fastcall TBox::SetBounds(int ALeft, int ATop, int AWidth, int
AHeight)
{
TWinControl::SetBounds(ALeft,ATop,AWidth,AHeight);
if( (FComboBox) && (FBitBtn) )
{
FComboBox->Height = AHeight;
FBitBtn->SetBounds(AWidth-19, 2, 17, AHeight-4);
}
}

>FBitBtn->SetBounds((FComboBox->Left+FComboBox->Width)
>-(FBitBtn->Width+2),FComboBox->Top+2,17,18);

It looks like you are trying to place the button on top of the ComboBox,
is
that correct? If so, why? Are you trying to custom-draw the combobox's
own
button, by chance?


Gambit


 

Re:Re: Design time positioning of child controls

"Paw Suddergaard" < XXXX@XXXXX.COM >wrote in message
Quote
Yes I am trying to create a Combobox that i am custom-drawing.
Then you should probably just derive from TComboBox itself and draw on the
ComboBox directly instead of trying to overlay another component on top of
it.
Gambit