Recent

Author Topic: [SOLVED]TShape is not resized after Parent Panel resizing  (Read 5718 times)

Bruce44

  • New Member
  • *
  • Posts: 15
[SOLVED]TShape is not resized after Parent Panel resizing
« on: October 03, 2016, 07:53:37 pm »
Hi
I have a TShape comp inside a TPanel. I try to set TShape position (Top, Left) and size (Width, Height) inside the onResize event of the panel (panel is resized itself by code inside the OnResize event of the form). The event is called, but any of the Left,Top,Width, Height has an effect on the TShape comp. If I installed a TStaticText or a TEdit inside the same panel, it works.

More strange, even without the Resize event, if I set Anchors set on TShape, It doesn't make it resized when parent panel is resized (it works with other component types)

It doesn't work also if I resize it directly from the OnResize event of the form (after panel size has been changed just before)
« Last Edit: October 04, 2016, 12:54:23 am by Bruce44 »

Handoko

  • Hero Member
  • *****
  • Posts: 5513
  • My goal: build my own game engine using Lazarus
Re: TShape is not resized after Parent Panel resizing
« Reply #1 on: October 03, 2016, 08:02:32 pm »
Can you please post you code here? And it will be better if you provide more info: screenshots, Lazarus version, OS, etc.

Bruce44

  • New Member
  • *
  • Posts: 15
Re: TShape is not resized after Parent Panel resizing
« Reply #2 on: October 03, 2016, 09:14:27 pm »
I made a simple test from an empty project in order to check if this problem still happens : A main form, a TPanel on it, a TShape inside the TPanel with anchors akBottom and akTop, and a button to resize the Panel
But the bug doesn't occur in that case : when I resize the panel by code when pressing the button, the TShape inside the TPanel is automatically resized.

In my app, the  form containing the TPanel and the TShape inside is embedded inside one panel which is embedded itself in the Main Form. I will investigate more...

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: TShape is not resized after Parent Panel resizing
« Reply #3 on: October 03, 2016, 09:56:07 pm »
panel is resized itself by code inside the OnResize event of the form
Do I understand correctly: In the OnResize event handler you call something which resizes the control again? Sounds very risky because the called Resize will trigger another OnResize event which will resize the control again etc. If the system does not crash this is a very unpredictable situation at least.
« Last Edit: October 03, 2016, 10:47:04 pm by wp »

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: TShape is not resized after Parent Panel resizing
« Reply #4 on: October 03, 2016, 10:33:02 pm »
I have a TShape comp inside a TPanel. I try to set TShape position (Top, Left) and size (Width, Height) inside the onResize event of the panel (panel is resized itself by code inside the OnResize event of the form). The event is called, but any of the Left,Top,Width, Height has an effect on the TShape comp.
I take it there is a typo there in that you meant nothing is happening. Now you wrote _has an effect_ (which is normal behaviour).

Quote
If I installed a TStaticText or a TEdit inside the same panel, it works.
It is unclear what works or what does not work. e.g. the colour of my handbag is ugly.

Quote
More strange, even without the Resize event, if I set Anchors set on TShape, It doesn't make it resized when parent panel is resized (it works with other component types)

It doesn't work also if I resize it directly from the OnResize event of the form (after panel size has been changed just before)
I can resize a shape manually based on a panel resize event. works perfectly for me. If i let the shape occupy client are it also resizes as expected.

Please state OS and Lazarus version and pretty very pretty please if it suits you, show us some code.

Bruce44

  • New Member
  • *
  • Posts: 15
Re: TShape is not resized after Parent Panel resizing
« Reply #5 on: October 03, 2016, 11:44:11 pm »
panel is resized itself by code inside the OnResize event of the form
Do I understand correctly: In the OnResize event handler you call something which resizes the control again? Sounds very risky because the called Resize will trigger another OnResize event which will resize the control again etc. If the system does not crash this is a very unpredictable situation at least.
No. In the OnResize event of the form, I change the Height of the Panel. There is no recursive call. But TShape controls inside this Panel are not resized automatically according to their anchors properties or if I set any of the Height, Top, Left, Width property of these TShape to another value (still from the OnResize event of the Form). Other controls types included in this panel are correctly resized (TPanel, TStaticText, ...).

Bruce44

  • New Member
  • *
  • Posts: 15
Re: TShape is not resized after Parent Panel resizing
« Reply #6 on: October 04, 2016, 12:19:25 am »
Wrong alert !
After analyzing the source code of one of the libraries provided with the appli, it appears that all TShape controls are reset to their original positions when resized.
So there is no LAZARUS bug, as I suspected it before, but just a programmer's bug !
Sorry for the disturb !
Is there a way to delete this complete post ? Because this one has no use indeed !

wp

  • Hero Member
  • *****
  • Posts: 13328
Re: TShape is not resized after Parent Panel resizing
« Reply #7 on: October 04, 2016, 12:20:39 am »
Why don't you write a simple demo which shows the issue? Then everybody knows what you are talking about (only pas, lfm, lpi and lpr files, packed together in a single zip).

Bruce44

  • New Member
  • *
  • Posts: 15
Re: TShape is not resized after Parent Panel resizing
« Reply #8 on: October 04, 2016, 12:51:00 am »
"Solved"
See reply#6

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: [SOLVED]TShape is not resized after Parent Panel resizing
« Reply #9 on: October 04, 2016, 02:26:38 am »
Wouldn't it be better to use the OnPaint event of the panel to redraw the shape after the resize ?
« Last Edit: October 04, 2016, 02:28:10 am by Zath »

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: [SOLVED]TShape is not resized after Parent Panel resizing
« Reply #10 on: October 04, 2016, 03:05:45 am »
Wouldn't it be better to use the OnPaint event of the panel to redraw the shape after the resize ?
Why ?

Code: [Select]
procedure TForm1.Panel1Resize(Sender: TObject);
begin
  Shape1.SetBounds(10,10,Panel1.Width - 20, Panel1.Height - 20);
end;
And the shape will repaint itself using the new size.

 

TinyPortal © 2005-2018