Hi, I have the following problem:
I'm trying to create a simple form at runtime where some are displayed TLabel
, and I need each one to be centered and at a certain height. I've been able to center them correctly using TLabel.Align := alClient
and TLabel.Alignment := taCenter
, but I can't get it to the height I need, because TLabel.Layout
it only lets me specify top, center, or bottom.
How can I assign TLabel
a height value like ClientHeight div 3
?
I have this code to create a label:
with TLabel.Create(Self) do
begin
Align := alClient;
Alignment := taCenter;
Top := (F.ClientHeight div 3) * 2;
caption:= 'Texto de la etiqueta';
Font.Size:= 18;
Font.Color := RGB(128, 0, 0);
Parent:= F;
end;
It seems that when applying Align
and Alignment
it ignores what I specify in Top
, then I don't know how to give it the desired value.
EDIT :
I am using Lazarus v1.6RC1
in Windows 10
. The app is also for Windows 10
.
Thanks in advance.
The problem is that if you are using as align for the component
TLabel.Align := alClient
, this will cause the component to automatically adjust (for its width and height) to take up all the available space of the containing component.This being the case, the width and height properties can no longer be assigned manually as comments (
label1.width := ClientHeight div 3
), because they will be ignored.You will have to change the alignment property (
TLabel.Align
) and then you can manually assign the width and height.ADDED: In the latest versions of delphi, there is a component called TGriPanelLayout that makes it easy to position multiple components on a form. Perhaps there is a similar one in Lazarus.
Sometimes it is interesting not to use Align or aligment ... without daring the anchor properties of each component, in case the form is resized where they are ...
I don't know if this will work for you...
http://wiki.freepascal.org/Anchor_Sides
Greetings.