如何在Delphi XE8中设置标签文本加粗

3

如何在 Delphi XE8 firemonkey 多设备项目中运行时将 TLabel 设置为粗体并恢复正常?

我已经尝试了以下方法,但不起作用:

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

也尝试过:

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

6

label.StyledSettings.Style 设置为false,然后它将遵循 Fontstyle 设置。

enter image description here

这里是一个在代码中切换StyledSettings.Style的示例代码(尽管我不记得曾经来回播放过这些。对我来说,在开始时只需进行一次设置)。

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;

要切换 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;

这是不可能的。只能更改label.styledsettings而不能更改styledsettings.style。 - Remi
我现在无法使用XE8进行检查。你的意思是在XE8中对象检查器没有显示StyledSettings吗? - Tom Brunberg
哦,是的,它在对象检查器中显示,但我想在运行时做到这一点。但谢谢,这样做起作用了。我怎样才能将文本从粗体改回正常? - Remi
你在设计时能做的事情也可以在运行时完成。将其改回来的方式也是相同的。 - Jerry Dodge

1

试试这个:

Label1.Font.Style := [fsBold];

我使用的是 Delphi 10.4。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接