FMXTFont (Delphi)
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 speed buttons TSpeedButton. 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
// Delphi procedure TForm1.FormCreate(Sender: TObject); begin Form1.Caption := 'FMX Font'; SpinBox1.Min := 6; SpinBox1.Max := 72; SpinBox1.Value := 12; SpinBox1.Increment := 3; SpinBox1.OnChange; end; procedure TForm1.ListBox1Click(Sender: TObject); begin Label1.Font.Family := ListBox1.Selected.Text; end; procedure TForm1.SpeedButton1Click(Sender: TObject); begin if (TFontStyle.fsBold in Label1.Font.Style) then Label1.Font.Style := Label1.Font.Style - [TFontStyle.fsBold] else Label1.Font.Style := Label1.Font.Style + [TFontStyle.fsBold]; end; procedure TForm1.SpeedButton2Click(Sender: TObject); begin if (TFontStyle.fsItalic in Label1.Font.Style) then Label1.Font.Style := Label1.Font.Style - [TFontStyle.fsItalic] else Label1.Font.Style := Label1.Font.Style + [TFontStyle.fsItalic]; end; procedure TForm1.SpeedButton3Click(Sender: TObject); begin if (TFontStyle.fsUnderline in Label1.Font.Style) then Label1.Font.Style := Label1.Font.Style - [TFontStyle.fsUnderline] else Label1.Font.Style := Label1.Font.Style + [TFontStyle.fsUnderline]; end; procedure TForm1.SpeedButton4Click(Sender: TObject); begin if (TFontStyle.fsStrikeOut in Label1.Font.Style) then Label1.Font.Style := Label1.Font.Style - [TFontStyle.fsStrikeOut] else Label1.Font.Style := Label1.Font.Style + [TFontStyle.fsStrikeOut]; end; procedure TForm1.SpinBox1Change(Sender: TObject); begin Label1.Font.Size := SpinBox1.Value; end;
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 )