Skip to main content
Table of Contents

TTMSFNCToolBar.AddButton Method

Creates and adds a TTMSFNCToolBarButton to the toolbar.

API unit family: TMSFNCToolBar Declaring type: TTMSFNCToolBar Inherited from: TTMSFNCCustomToolBar

Syntax

FMX.TMSFNCToolBar.hppPascalC++
function AddButton(AWidth: Single = -1; AHeight: Single = -1; AResource: String = ''; AResourceLarge: String = ''; AText: String = ''; AIndex: Integer = -1): TTMSFNCToolBarButton; overload; virtual;
virtual TTMSFNCToolBarButton* __fastcall AddButton(float AWidth = -1.000000E+00f, float AHeight = -1.000000E+00f, System::UnicodeString AResource = System::UnicodeString(), System::UnicodeString AResourceLarge = System::UnicodeString(), System::UnicodeString AText = System::UnicodeString(), int AIndex = 0xffffffff)/* overload */;

Parameters

Name Description
AWidth Button width in pixels, or -1 to use the default.
AHeight Button height in pixels, or -1 to use the default.
AResource Bitmap resource name for the normal state.
AResourceLarge Bitmap resource name for the large-layout state.
AText Caption text shown on the button.
AIndex Zero-based insertion index, or -1 to append.

Returns

The newly created button.

Usage examples

Add toolbar buttons and picker controls

Creates a button, separator, font-size picker, and color picker in code.

Add toolbar buttons and picker controlsPascalC++
procedure TForm1.ConfigureToolbar;
var
  Button: TTMSFNCToolBarButton;
begin
  TMSFNCToolBar1.AutoAlign := True;
  TMSFNCToolBar1.AutoSize := True;

  Button := TMSFNCToolBar1.AddButton(96, 32, '', '', 'Refresh');
  Button.OnClick := RefreshButtonClick;

  TMSFNCToolBar1.AddSeparator;
  TMSFNCToolBar1.AddFontSizePicker;
  TMSFNCToolBar1.AddColorPicker;
end;

procedure TForm1.RefreshButtonClick(Sender: TObject);
begin
  ShowMessage('Refresh the current view.');
end;
void __fastcall TForm1::ConfigureToolbar()
{
  TMSFNCToolBar1->AutoAlign = true;
  TMSFNCToolBar1->AutoSize = true;

  TTMSFNCToolBarButton *Button = TMSFNCToolBar1->AddButton(96, 32, "", "", "Refresh");
  Button->OnClick = RefreshButtonClick;

  TMSFNCToolBar1->AddSeparator();
  TMSFNCToolBar1->AddFontSizePicker();
  TMSFNCToolBar1->AddColorPicker();
}

void __fastcall TForm1::RefreshButtonClick(TObject *Sender)
{
  ShowMessage("Refresh the current view.");
}

Read the related guide

Build a document-editor formatting toolbar

Creates file buttons, a separator, font-name/size and color pickers, and wires each picker's typed selection event to a memo.

Build a document-editor formatting toolbarPascalC++
procedure TForm1.BuildEditorToolBar;
var
  btnNew, btnOpen, btnSave: TTMSFNCToolBarButton;
  fontName: TTMSFNCToolBarFontNamePicker;
  fontSize: TTMSFNCToolBarFontSizePicker;
  textColor: TTMSFNCToolBarColorPicker;
begin
  TMSFNCToolBar1.BeginUpdate;
  try
    // Let the toolbar size and align its content automatically.
    TMSFNCToolBar1.AutoSize := True;
    TMSFNCToolBar1.AutoAlign := True;

    // File commands. Keep the returned button to wire its OnClick.
    btnNew := TMSFNCToolBar1.AddButton(-1, -1, '', '', 'New');
    btnNew.OnClick := FileNewClick;
    btnOpen := TMSFNCToolBar1.AddButton(-1, -1, '', '', 'Open');
    btnOpen.OnClick := FileOpenClick;
    btnSave := TMSFNCToolBar1.AddButton(-1, -1, '', '', 'Save');
    btnSave.OnClick := FileSaveClick;

    // Visual break between the file group and the formatting group.
    TMSFNCToolBar1.AddSeparator;

    // Built-in pickers. Each raises a typed selection event.
    fontName := TMSFNCToolBar1.AddFontNamePicker;
    fontName.SelectedFontName := 'Segoe UI';
    fontName.OnFontNameSelected := FontNameSelected;

    fontSize := TMSFNCToolBar1.AddFontSizePicker;
    fontSize.SelectedFontSize := 11;
    fontSize.OnFontSizeSelected := FontSizeSelected;

    textColor := TMSFNCToolBar1.AddColorPicker;
    textColor.OnColorSelected := TextColorSelected;
  finally
    TMSFNCToolBar1.EndUpdate;
  end;
  TMSFNCToolBar1.Build;
end;

procedure TForm1.FontNameSelected(Sender: TObject; AFontName: string);
begin
  Memo1.TextSettings.Font.Family := AFontName;
end;

procedure TForm1.FontSizeSelected(Sender: TObject; AFontSize: Single);
begin
  Memo1.TextSettings.Font.Size := AFontSize;
end;

procedure TForm1.TextColorSelected(Sender: TObject; AColor: TTMSFNCGraphicsColor);
begin
  Memo1.TextSettings.FontColor := AColor;
end;
void __fastcall TForm1::BuildEditorToolBar()
{
  TMSFNCToolBar1->BeginUpdate();
  try
  {
    // Let the toolbar size and align its content automatically.
    TMSFNCToolBar1->AutoSize = true;
    TMSFNCToolBar1->AutoAlign = true;

    // File commands. Keep the returned button to wire its OnClick.
    TTMSFNCToolBarButton *btnNew = TMSFNCToolBar1->AddButton(-1, -1, "", "", "New");
    btnNew->OnClick = FileNewClick;
    TTMSFNCToolBarButton *btnOpen = TMSFNCToolBar1->AddButton(-1, -1, "", "", "Open");
    btnOpen->OnClick = FileOpenClick;
    TTMSFNCToolBarButton *btnSave = TMSFNCToolBar1->AddButton(-1, -1, "", "", "Save");
    btnSave->OnClick = FileSaveClick;

    // Visual break between the file group and the formatting group.
    TMSFNCToolBar1->AddSeparator();

    // Built-in pickers. Each raises a typed selection event.
    TTMSFNCToolBarFontNamePicker *fontName = TMSFNCToolBar1->AddFontNamePicker();
    fontName->SelectedFontName = "Segoe UI";
    fontName->OnFontNameSelected = FontNameSelected;

    TTMSFNCToolBarFontSizePicker *fontSize = TMSFNCToolBar1->AddFontSizePicker();
    fontSize->SelectedFontSize = 11;
    fontSize->OnFontSizeSelected = FontSizeSelected;

    TTMSFNCToolBarColorPicker *textColor = TMSFNCToolBar1->AddColorPicker();
    textColor->OnColorSelected = TextColorSelected;
  }
  __finally
  {
    TMSFNCToolBar1->EndUpdate();
  }
  TMSFNCToolBar1->Build();
}

void __fastcall TForm1::FontNameSelected(TObject *Sender, System::UnicodeString AFontName)
{
  Memo1->TextSettings->Font->Family = AFontName;
}

void __fastcall TForm1::FontSizeSelected(TObject *Sender, float AFontSize)
{
  Memo1->TextSettings->Font->Size = AFontSize;
}

void __fastcall TForm1::TextColorSelected(TObject *Sender, TTMSFNCGraphicsColor AColor)
{
  Memo1->TextSettings->FontColor = AColor;
}

Read the related guide