RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TToolBar.ShowCaptions Property

Determines whether text captions are displayed on tool buttons.

Pascal
property ShowCaptions: Boolean;
C++
__property Boolean ShowCaptions;

If ShowCaptions is set to true, tool buttons appear in the toolbar with their captions displayed. Setting ShowCaptions to true may increase the size of the tool buttons.  

C++ Examples: 

 

/*
To create a toolbar that corresponds to an existing menu:

1   Drop a ToolBar on the form and add a ToolButton for each
  top-level menu item you wish to create.
2   Set the MenuItem property of each ToolButton to correspond
  to the top level menu items.
3   Set the Grouped property of each ToolButton to true.
4   Clear the Menu property of the Form (if it is assigned)
5   Set the Visible property on the ToolBar and ToolButtons to
  true.
6   Set the ShowCaptions property on the ToolBar to true.
7   Set the MenuItem | Visible property of each ToolButton to
  true.
*/
/*
This example creates a ToolBar and adds ToolButtons to it.
Include ComCtlrs in the uses clause.
*/
#include <comctrls.hpp>

void AddButtons(TToolBar *toolBar, TStringList *captions)
{
  for (int i = 0; i < captions->Count; i++)
  {
    TToolButton *button = new TToolButton(toolBar);
    button->Parent = toolBar;
    button->Caption = captions->Strings[i];
    if (button->Caption == "|")
      button->Style = tbsSeparator;
    else
      button->Style = tbsButton;
  }
}

TToolBar *myToolBar;

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  myToolBar = new TToolBar(this);
  myToolBar->Parent = this;
  TStringList *captions = new TStringList();
  captions->Add("New");
  captions->Add("Save");
  captions->Add("|");
  captions->Add("Cut");
  captions->Add("Copy");
  captions->Add("Paste");
  AddButtons(myToolBar, captions);
  delete captions;
  myToolBar->ShowCaptions = True;
  myToolBar->Height = 40;
}

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
  for (int I = myToolBar->ButtonCount - 1; I >= 0; I--)
    delete myToolBar->Buttons[I];
  delete myToolBar;
}

 

Delphi Examples: 

{
To create a toolbar that corresponds to an existing menu:

1   Drop a ToolBar on the form and add a ToolButton for each top-level menu item you wish to create.
2   Set the MenuItem property of each ToolButton to correspond to the top level menu items.
3   Set the Grouped property of each ToolButton to true.
4   Clear the Menu property of the Form (if it is assigned)
5   Set the Visible property on the ToolBar and ToolButtons to true.
6   Set the ShowCaptions property on the ToolBar to true.
7   Set the MenuItem | Visible property of each ToolButton to true.
}
{
This example creates a ToolBar and adds ToolButtons to it.
Include ComCtlrs in the uses clause.
}
procedure AddButtons(ToolBar: TToolBar;
  Const ButtonCaptions: array of String);
var
  I: Integer;
begin
  for I := 0 to High(ButtonCaptions) do
    begin
      with TToolButton.Create(ToolBar) do
      begin
        Parent := ToolBar;
        Caption := ButtonCaptions[I];
        if (ButtonCaptions[I] = '|') then
          Style := tbsSeparator
        else
          Style := tbsButton;
      end;
    end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ToolBar1 := TToolBar.Create(Self);
  ToolBar1.Parent := Self;
  AddButtons(ToolBar1, ['New', 'Save', '|', 'Cut', 'Copy', 'Paste']);
  ToolBar1.ShowCaptions := True;
  ToolBar1.Height := 40;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  I: Integer;
begin
  for I := ToolBar1.ButtonCount - 1 downto 0 do
    ToolBar1.Buttons[I].Free;
  ToolBar1.Free;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!