FMXTFont (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

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.

TFont new1.JPG

Code

// Delphi

procedure TForm1.FormCreate(Sender: TObject);
begin
  Form1.Caption := 'FMX Font';
  Label1.StyledSettings := [];
  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

See Also