FMXTFont (C++)
From RAD Studio Code Examples
Contents |
Description
This example demonstrates how to use different properties of TFont.
This example requires the following components:
- A 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.
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
- FMX.Types.TFont.Style ( fr | de | ja )
- FMX.Types.TFont.Size ( fr | de | ja )
- FMX.Types.TFont.Family ( fr | de | ja )
- FMX.StdCtrls.TLabel ( fr | de | ja )
- FMX.StdCtrls.TSpeedButton ( fr | de | ja )
- FMX.Edit.TSpinBox ( fr | de | ja )
- FMX.ListBox.TListBox ( fr | de | ja )
- FMX.ListBox.TListBoxItem ( fr | de | ja )
- System.UITypes.TFontName ( fr | de | ja )
- System.UITypes.TFontStyles ( fr | de | ja )
- System.UITypes.TFontStyle ( fr | de | ja )
- FMX.Controls.TControl.OnClick ( fr | de | ja )