Recent

Author Topic: Where is my control?  (Read 792 times)

hakelm

  • Full Member
  • ***
  • Posts: 173
Where is my control?
« on: October 31, 2022, 04:11:07 pm »
I have a control, say tlabel, with autosize set.
I fill the label with text so that the size changes.
None of the properties Width, Height or ClientWidth, ClientHeight  or ClientRect do change before the parent is resized.
Why is this so and how do I find out where my control is and how big it is without resizing the parent?
H

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Where is my control?
« Reply #1 on: October 31, 2022, 04:22:16 pm »
Generally speaking, autosizing works best if the container of the autosized control is also autosized.

wp

  • Hero Member
  • *****
  • Posts: 13583
Re: Where is my control?
« Reply #2 on: October 31, 2022, 05:21:48 pm »
I have a control, say tlabel, with autosize set.
I fill the label with text so that the size changes.
None of the properties Width, Height or ClientWidth, ClientHeight  or ClientRect do change before the parent is resized.
I don't think that this is true.

Drop a TLabel on the form (not auto-sized), it has AutoSize=true by default. See the eight grabbers around the label? Type some text into the Caption property of the label - look at the label and see the right grabbers moving. Scroll the Object Inspector to see the Width property of the label. Note that Width changes after each change of the Caption text.

This is on Windows. What is your OS?

hakelm

  • Full Member
  • ***
  • Posts: 173
Re: Where is my control?
« Reply #3 on: October 31, 2022, 07:03:29 pm »
Thanks, resizing seems necessary, at least on Lazarus 2.2.0 running under my Ubuntu 22.04:

The little program excerpt below:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   writeln(label1.Width,'/',label1.Height);
  4.   writeln(label1.ClientWidth,'/',label1.ClientHeight);
  5.   writeln(label1.ClientRect.Bottom,'/',label1.ClientHeight);
  6.   label1.caption:=memo1.Lines.Text;
  7.   application.ProcessMessages;
  8.   writeln('After application.ProcessMessages, Before FormResize:');
  9.   writeln(label1.Width,'/',label1.Height);
  10.   writeln(label1.ClientWidth,'/',label1.ClientHeight);
  11.   writeln(label1.ClientRect.Bottom,'/',label1.ClientHeight);
  12. end;
  13.  
  14. procedure TForm1.FormResize(Sender: TObject);
  15. begin
  16.   writeln('After FormResize:');
  17.   writeln(label1.Width,'/',label1.Height);
  18.   writeln(label1.ClientWidth,'/',label1.ClientHeight);
  19.   writeln(label1.ClientRect.Bottom,'/',label1.ClientHeight);
  20. end;  

produces
Code: Pascal  [Select][+][-]
  1. 45/17
  2. 45/17
  3. 17/17
  4. After application.ProcessMessages, Before FormResize:
  5. 45/17
  6. 45/17
  7. 17/17
  8. After FormResize:
  9. 616/476
  10. 616/476
  11. 476/476
in the console.

H

 

TinyPortal © 2005-2018