How to set label text bold in delphi Xe8

19k Views Asked by At

How can you set a TLabel to Bold and back to normal runtime in Delphi XE8 firemonkey multi device project?

I've tried this but it doesn't work:

label.TextSettings.Font.Style := [TFontStyle.fsBold];

Also tried:

label.Font.Style := [TFontStyle.fsBold];
2

There are 2 best solutions below

4
Tom Brunberg On BEST ANSWER

Set label.StyledSettings.Style false, then it will follow the Fontstyle settings.

enter image description here

Here a sample code to toggle StyledSettings.Stylewith in code (although I don't remember that I've ever played back and forth with these. For me it's more a one time setup at start).

procedure TForm6.Button9Click(Sender: TObject);
begin
  if TStyledSetting.Style in Label3.StyledSettings then
    Label3.StyledSettings := Label3.StyledSettings - [TStyledSetting.Style]
  else
    Label3.StyledSettings := Label3.StyledSettings + [TStyledSetting.Style]
end;

And to toggle the TextSettings.Font.Style

procedure TForm6.Button8Click(Sender: TObject);
begin
  if TFontStyle.fsBold in Label3.TextSettings.Font.Style then
    Label3.TextSettings.Font.Style := Label3.TextSettings.Font.Style - [TFontStyle.fsBold]
  else
    Label3.TextSettings.Font.Style := Label3.TextSettings.Font.Style + [TFontStyle.fsBold];
end;
0
Alaaeldin Mustafa On

Try this:

Label1.Font.Style := [fsBold];

I used delphi 10.4.