Jump to content
JimKueneman

Dynamically Created Label Font Change

Recommended Posts

Hi, 

 

Delphi 11.2 Patch 1, FireMonkey app running in Windows 11 in a virtual Machine on OSX.  Does not work compiled into Linux or OSX either.

 

procedure TForm1.Button4Click(Sender: TObject);
var
  L: TLabel;
begin
  Label1.TextSettings.Font.Style := [TFontStyle.fsBold];  // Desiger Dropped Label is Bold
  L := TLabel.Create(Self);
  L.Text := 'Testing';
  L.Align := TAlignLayout.Bottom;
  L.TextSettings.Font.Style := [TFontStyle.fsBold];  // Dynamically created Label is not Bold
  L.Parent := Layout1;
end;

Why won't the dynamically added Label respond to changing TextSettings.Font.Style?

 

Jim

Edited by JimKueneman

Share this post


Link to post

Most probably you've changed the Label1.StyledSettings property. I've tried with the default settings of the TLabel you cannot change the style from the code.

 

In order to work you have to add:

L.StyledSettings:=L.StyledSettings-[TStyledSetting.Style];

 

 

  • Like 1

Share this post


Link to post

I have the same problem in Delphi 12. I tried to add the line L.StyledSettings:=L.StyledSettings-[TStyledSetting.Style];

but no change.

 Panel1 :=  TPanel.Create(self);
                          Panel1.Height := 49;
                          Panel1.Parent := FramedVertScrollBox1;
                          Panel1.Align := TAlignLayout.Top;
                          Panel1.StyleLookup := 'calloutpanelstyle';
                          Panel1.Height := 60;
                          L1 := Tlabel.Create(self);
                          L1.Parent := Panel1;
                          L1.Width := 150;
                          L1.Height := 38;
                          L1.Align := TAlignLayout.Left;
                          L1.Margins.Left := 15;
                          L1.Margins.Top := 10;
                          L1.TextSettings.Font.Family := 'Segoe UI Semibold';
                          L1.TextSettings.Font.Size :=30;
                          L1.Text := JSONItems.Items[i].GetValue<string>('ticketnr');
                          L2 := Tlabel.Create(self);
                          L2.Parent := Panel1;
                          L2.Width := 150;
                          L2.Height := 38;
                          L2.Margins.Top := 10;
                          L2.Align := TAlignLayout.Right;
                          L2.TextSettings.Font.Family := 'Segoe UI Semibold';
                          L2.TextSettings.Font.Size :=30;
                          L2.Text := DateToStr(ISO8601ToDate(JSONItems.Items[i].GetValue<string>('invdate')));
                          L1.StyledSettings:=L1.StyledSettings-[TStyledSetting.Style];
                          L2.StyledSettings:=L2.StyledSettings-[TStyledSetting.Style];

The font size dosen't change.

Share this post


Link to post

The answer is the same as for the previous question you have to change the StyledSettings. In this case you are changing the Family and Style thus you have to remove those elements from the set, you do not change the Style of the font.

 

You can replace:

 

L1.StyledSettings:=L1.StyledSettings-[TStyledSetting.Style];
L2.StyledSettings:=L2.StyledSettings-[TStyledSetting.Style];

 

with:

 

                          L1.StyledSettings:=[];
                          L2.StyledSettings:=[];
 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×