Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TWinControl::CreateParams hides grand children controls if resized


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Dec 13, 2014 12:59 AM Last Post By: CN Liou
CN Liou

Posts: 8
Registered: 7/18/03
TWinControl::CreateParams hides grand children controls if resized  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 7:13 PM
I am trying to horizontally flip controls. The following code seems to work except for the problem that the control placed on TGroupBox disappears when TForm is resized.

It appears that it is CreateParams() that is making the trouble.

How to prevent the control on TGroupBox from being hidden when the form is resized?

Thanks!
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
	gb=new TGroupBox(this);
	gb->Parent=this;
	gb->Align=alTop;
	gb->Height=200;
 
	TEdit *edit=new TEdit(this);
	edit->Parent=gb; //Hidden if TForm is resized.
	edit->Top=10;
	edit->Left=10;
	edit->Text="On TGroupBox";
	gb->FlipChildren(true);
 
	edit=new TEdit(this);
	edit->Parent=this; //Works as expected - remaining visible.
	edit->Top=210;
	edit->Left=10;
	edit->Text="On TForm";
}
 
//Flip TForm::Caption.
void __fastcall TForm1::CreateParams(TCreateParams &Params)
{
  TForm::CreateParams(Params);
  Params.ExStyle=Params.ExStyle | WS_EX_LEFT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT;
}
 
void __fastcall TForm1::FormResize(TObject *Sender)
{
	PaintControls(gb->Handle,NULL); //This does not help.
}
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TWinControl::CreateParams hides grand children controls if resized  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 9:38 PM   in response to: CN Liou in response to: CN Liou
CN wrote:

I am trying to horizontally flip controls. The following code seems to
work except for the problem that the control placed on TGroupBox
disappears when TForm is resized.

You are not taking Anchors into account. FlipChildren() adjusts each child
control's Left and Align properties, nothing else. It does not update the
Anchors property to match. The Anchors property is set to [akLeft, akTop]
by default. So when your TGroupBox flips the TEdit, the TEdit is still anchored
to the TGroupBox's top-left corner, which is why the TEdit does not move
when the TGroupBox is resized.

You can verify this at design-time. Drop a control onto your Form, note
the control's current Anchors, then right-click on the Form and choose "Flip
Children". The control will flip, but look at its Anchors and you will see
that they have not changed.

You need to adjust the TEdit's Anchors manually after flipping, eg:

gb.FlipChildren(True);
edit.Anchors := edit.Anchors - [akLeft] + [akRight];


It appears that it is CreateParams() that is making the trouble.

The problem has nothing to do with CreateParams().

--
Remy Lebeau (TeamB)
..
CN Liou

Posts: 8
Registered: 7/18/03
Re: TWinControl::CreateParams hides grand children controls if resized  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 11:44 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
You need to adjust the TEdit's Anchors manually after flipping, eg:

gb.FlipChildren(True);
edit.Anchors := edit.Anchors - [akLeft] + [akRight];

Right! This adjustment yields more useful effect when the form is resized.
However, it does not fix the problem - the controls on TGroupBox being hidden.

The problem has nothing to do with CreateParams().

The control on TGroupBox remains visible if this line is commented out:
Params.ExStyle=Params.ExStyle | WS_EX_LEFT | WS_EX_RTLREADING | 
WS_EX_LEFTSCROLLBAR | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT;

I suspect there is something wrong among the WS_EX switches.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: TWinControl::CreateParams hides grand children controls if resized  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2014 9:10 AM   in response to: CN Liou in response to: CN Liou
CN wrote:

Right! This adjustment yields more useful effect when the form is
resized. However, it does not fix the problem - the controls on
TGroupBox being hidden.

Worked fine for me. What are the EXACT steps to reproduce? Can you provide
screenshots?

--
Remy Lebeau (TeamB)
CN Liou

Posts: 8
Registered: 7/18/03
Re: TWinControl::CreateParams hides grand children controls if resized  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 13, 2014 12:45 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Worked fine for me. What are the EXACT steps to reproduce? Can you provide
screenshots?
I thought that it was TEdit on TGroupBox that disappeared if the form is resized. My observation was incorrect.
By painting green color on TGroupBox, now I know it is TGroupBox that disappears.

The complete code follows:

Unit1.h:
class TForm1 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
		TGroupBox *gb;
        void __fastcall CreateParams(TCreateParams &Params);
public:		// User declarations
        __fastcall TForm1(TComponent* Owner);
};

Unit1.cpp:
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
	Width=400;
	Height=150;
 
	gb=new TGroupBox(this);
	gb->Parent=this;
	gb->Align=alTop;
	gb->Height=50;
	gb->Color=clLime;
 
	TEdit *edit=new TEdit(this);
	edit->Parent=gb;
	edit->Top=10;
	edit->Left=10;
	edit->Text="On TGroupBox";
 
	gb->FlipChildren(true);
	edit->Anchors=edit->Anchors >> akLeft;
	edit->Anchors=edit->Anchors << akRight;
 
	edit=new TEdit(this);
	edit->Parent=this;
	edit->Top=55;
	edit->Left=10;
	edit->Text="On TForm";
}
//---------------------------------------------------------------------------
//Force TForm::Caption to align right.
void __fastcall TForm1::CreateParams(TCreateParams &Params)
{
	TForm::CreateParams(Params);
	Params.ExStyle = Params.ExStyle | WS_EX_LEFT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR | WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT;
}

Pressing F9 in BCB6 IDE will reproduce the following results:

(a1) with CreateParams(), original, perfect:
https://dl.dropboxusercontent.com/u/20612585/CreateParams.png

(a2) with CreateParams(), TGroupBox disappeared after form is resized:
https://dl.dropboxusercontent.com/u/20612585/CreateParams-dragged.png
Several tiny portions (borders?) of TGroupBox jitter when the form is being resized. After the resizing stops, TGroupBox completely disappears.

These screenshots show correct results though the alignments of form caption and TEdit on the form are not as desired:
(b1) without CreateParams(), original:
https://dl.dropboxusercontent.com/u/20612585/no-CreateParams.png

(b2) without CreateParams(), after form is resized:
https://dl.dropboxusercontent.com/u/20612585/no-CreateParams-dragged.png

I run BCB6 and this Project1.exe in Windows XP within Virtualbox.

Edited by: CN Liou on Dec 13, 2014 12:53 AM
Link mechanism seems to be not working.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02