在 C++ 中以编程方式设置 Firemonkey 控制字体

Setting Firemonkey control font programmatically in C++

我有一个扩展 TEdit 的自定义 Firemonkey 控件,它是在表单上动态创建的。我试图在使用以下方法创建它时设置它的字体大小:

Search->Font->Size = 15;

但是,字体在控件上保持不变。

我有另一个相同类型的控件,它已经在窗体上,我可以通过编程更改字体大小。我注意到这个控件,如果 StyledSettings 属性中的 Size 设置设置为 false,我可以更改字体,而如果 Size 设置设置为 true,我不能更改字体大小。

因此,当我创建自定义控件时,我试图以编程方式将 Size 属性 设置为 false,但我不知道如何操作。

我试过:

Search->StyledSettings.Size = false;

Search->StyledSettings = ListBox->StyledSettings - [TStyledSetting.ssSize];

两者都不会编译。我怎样才能确保 属性 在 运行 时从我的自定义控件中删除?或者还有其他方法可以设置它的字体吗?

However, the font remains unchanged on the control.

I have another control of the same type that is already on the form which I can change the font size programmatically. I noticed with this control, that if the Size setting is set to false in the StyledSettings properties I can change the font, whereas if the Size setting is set to true, I cannot change the font size.

这是记录在案的行为:

Using the StyledSettings Property

When changing text representation properties of the TTextSettings type objects, remember that when you are changing the value of a property (of the TextSettings.Font.Size property in the previous example), then the actual changing of the object's view happens only if the ITextSettings.StyledSettings property does not contain the TStyledSetting.Size constant. The "Relation between TStyledSetting constants and TTextSettings properties" table shows which TStyledSetting constants control handling of the TTextSettings text representation properties.

FMX.Graphics.ITextSettings

Remember that when you are changing the value of a property (for example of the TextSettings.FontColor property), then the actual changing of the control's view happens only if the StyledSettings property does not contain the TStyledSetting.FontColor constant. The following table shows which TStyledSetting constants control handling of which TTextSettings text representation properties.

Relation between TStyledSetting constants and TTextSettings properties

TStyledSetting   Dependent TTextSettings   Meaning 
   Constant             Properties

Family           TFont.Family              Font name. 
Size             TFont.Size                Font size. 
Style            TFont.Style               Font style (italic, bold). 
FontColor        FontColor                 Font color. 
Other            HorzAlign, VertAlign,     How to align and show the text.  
                 Trimming, and WordWrap.

So, when I create my custom control, I am trying to programmatically set the Size property to false, however I cannot figure out how to do so.

C++ 中正确的语法是:

Search->StyledSettings = Search->StyledSettings >> TStyledSetting::Size;