设置字体设置不适用于创建动态标签
Set font settings dont works on create dynamic Label
我试图在动态创建的 TLabel
对象中设置字体颜色和字体大小,但它不起作用。
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TLabel *text;
text = new TLabel(Form1);
text->Parent = Form1;
text->Align = TAlignLayout::Center;
text->Margins->Top = 60;
text->Font->Size = 13; // don't works
text->FontColor = TColorRec::Red; // don't works
text->Height = 17;
text->Width = 120;
text->TextSettings->HorzAlign = TTextAlign::Center;
text->TextSettings->VertAlign = TTextAlign::Leading;
text->StyledSettings.Contains(TStyledSetting::Family);
text->StyledSettings.Contains(TStyledSetting::Style);
text->Text = "My Text";
text->VertTextAlign = TTextAlign::Leading;
text->Trimming = TTextTrimming::None;
text->TabStop = false;
text->SetFocus();
}
结果:
您不是为了启用自己的设置而从 TStyledSettings
中删除项目。参见
但是你也使用了错误的颜色常量。而不是 TColorRec::Red
你应该使用 TAlphaColor(claRed)
这个有效:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TLabel *text;
text = new TLabel(Form1);
text->Parent = Form1;
text->Position->X = 8;
text->Position->Y = 50;
text->Text = "My Text";
// clear all styled settings to enable your own settings
// text->StyledSettings = TStyledSettings(NULL);
// alternatively clear only styled font color setting
text->StyledSettings = text->StyledSettings >> TStyledSetting::FontColor;
// and styled size setting
text->StyledSettings = text->StyledSettings >> TStyledSetting::Size;
// Firemonkey uses TAlphaColor colors
text->FontColor = TAlphaColor(claRed);
// alternatively:
// text->FontColor = TAlphaColor(TAlphaColorRec::Red);
// text->FontColor = TAlphaColor(0xFFFF0000); // ARGB
text->Height = 20;
text->Font->Size = 15; // works now
}
我试图在动态创建的 TLabel
对象中设置字体颜色和字体大小,但它不起作用。
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TLabel *text;
text = new TLabel(Form1);
text->Parent = Form1;
text->Align = TAlignLayout::Center;
text->Margins->Top = 60;
text->Font->Size = 13; // don't works
text->FontColor = TColorRec::Red; // don't works
text->Height = 17;
text->Width = 120;
text->TextSettings->HorzAlign = TTextAlign::Center;
text->TextSettings->VertAlign = TTextAlign::Leading;
text->StyledSettings.Contains(TStyledSetting::Family);
text->StyledSettings.Contains(TStyledSetting::Style);
text->Text = "My Text";
text->VertTextAlign = TTextAlign::Leading;
text->Trimming = TTextTrimming::None;
text->TabStop = false;
text->SetFocus();
}
结果:
您不是为了启用自己的设置而从 TStyledSettings
中删除项目。参见
但是你也使用了错误的颜色常量。而不是 TColorRec::Red
你应该使用 TAlphaColor(claRed)
这个有效:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TLabel *text;
text = new TLabel(Form1);
text->Parent = Form1;
text->Position->X = 8;
text->Position->Y = 50;
text->Text = "My Text";
// clear all styled settings to enable your own settings
// text->StyledSettings = TStyledSettings(NULL);
// alternatively clear only styled font color setting
text->StyledSettings = text->StyledSettings >> TStyledSetting::FontColor;
// and styled size setting
text->StyledSettings = text->StyledSettings >> TStyledSetting::Size;
// Firemonkey uses TAlphaColor colors
text->FontColor = TAlphaColor(claRed);
// alternatively:
// text->FontColor = TAlphaColor(TAlphaColorRec::Red);
// text->FontColor = TAlphaColor(0xFFFF0000); // ARGB
text->Height = 20;
text->Font->Size = 15; // works now
}