Forum > LCL

Where is my control?

(1/1)

hakelm:
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:
Generally speaking, autosizing works best if the container of the autosized control is also autosized.

wp:

--- Quote from: hakelm 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.

--- End quote ---
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:
Thanks, resizing seems necessary, at least on Lazarus 2.2.0 running under my Ubuntu 22.04:

The little program excerpt below:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin  writeln(label1.Width,'/',label1.Height);  writeln(label1.ClientWidth,'/',label1.ClientHeight);  writeln(label1.ClientRect.Bottom,'/',label1.ClientHeight);  label1.caption:=memo1.Lines.Text;  application.ProcessMessages;  writeln('After application.ProcessMessages, Before FormResize:');  writeln(label1.Width,'/',label1.Height);  writeln(label1.ClientWidth,'/',label1.ClientHeight);  writeln(label1.ClientRect.Bottom,'/',label1.ClientHeight);end; procedure TForm1.FormResize(Sender: TObject);begin  writeln('After FormResize:');  writeln(label1.Width,'/',label1.Height);  writeln(label1.ClientWidth,'/',label1.ClientHeight);  writeln(label1.ClientRect.Bottom,'/',label1.ClientHeight);end;  
produces

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---45/1745/1717/17After application.ProcessMessages, Before FormResize:45/1745/1717/17After FormResize:616/476616/476476/476in the console.

H

Navigation

[0] Message Index

Go to full version