How do I set the properties of FireMonkey's TFont in C++Builder?

By: Tim DelChiaro

Abstract: This example demonstrates how to set the font family, style and size in TFont

    FMXTFont (C++)

 

    Language:

    Versions:

 

Contents

    Description

This example demonstrates how to use different properties of TFont.

This example requires the following components:

  • TListBox with a number of items (TListBoxItem). Set the items' text to common font names.
  • Four TSpeedButton speed buttons. Set their text to B, I, U, S and their font style to Bold, Italic, Underline, Strikeout, respectively.
  • A spin box (TSpinBox)
  • A label (TLabel)

Create an OnClick event handler for the TSpeedButtons by double-clicking them in Design mode.

The form should look like in the following image.

File:TFont_new1.JPG

    Code

// C++
 
void __fastcall TForm2::FormCreate(TObject *Sender) {
	Form2->Caption = "FMX Font";
	SpinBox1->Min = 6;
	SpinBox1->Max = 72;
	SpinBox1->Value = 12;
	SpinBox1->Increment = 3;
	SpinBox1->OnChange;
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm2::ListBox1Click(TObject *Sender) {
	Label1->Font->Family = ListBox1->Selected->Text;
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm2::SpeedButton1Click(TObject *Sender) {
        // fsBold
	TFontStyles AStyle(1);
	if (Label1->Font->Style.Contains(TFontStyle::fsBold))
		Label1->Font->Style = Label1->Font->Style - AStyle;
	else
		Label1->Font->Style = Label1->Font->Style + AStyle;
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm2::SpeedButton2Click(TObject *Sender) {
        // fsItalic
	TFontStyles AStyle(2);
	if (Label1->Font->Style.Contains(TFontStyle::fsItalic))
		Label1->Font->Style = Label1->Font->Style - AStyle;
	else
		Label1->Font->Style = Label1->Font->Style + AStyle;
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm2::SpeedButton3Click(TObject *Sender) {
        // fsUnderline
	TFontStyles AStyle(4);
	if (Label1->Font->Style.Contains(TFontStyle::fsUnderline))
		Label1->Font->Style = Label1->Font->Style - AStyle;
	else
		Label1->Font->Style = Label1->Font->Style + AStyle;
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm2::SpeedButton4Click(TObject *Sender) {
        // fsStrikOut
	TFontStyles AStyle(8);
	if (Label1->Font->Style.Contains(TFontStyle::fsStrikeOut))
		Label1->Font->Style = Label1->Font->Style - AStyle;
	else
		Label1->Font->Style = Label1->Font->Style + AStyle;
 
}
// ---------------------------------------------------------------------------
 
void __fastcall TForm2::SpinBox1Change(TObject *Sender) {
	Label1->Font->Size = SpinBox1->Value;
}
// ---------------------------------------------------------------------------

    Uses

    See Also

Server Response from: ETNASC04