delphifontsfiremonkeydelphi-xe8tlabel

How to set label text bold in delphi Xe8


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];

Solution

  • 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;