Topic: How to Show Caption In Toolbutton

I Try Create Toolbar and Toolbutton By Array Of TToolbutton
----
Create ToolBar OK
Create TToolbutton OK
But Not Show Caption  In TToolbutton

How to Show Caption In Toolbutton ?

var
toolbar : Ttoolbar ;
toolbar_list : array of TToolbutton ;
i : Integer ;
begin
    toolbar := Ttoolbar.Create(Form1) ;
    toolbar.Parent := Form1.Panel1 ;
    toolbar.showcaptions := true;
    toolbar.Autosize := True ;
    toolbar_list := ['AAA','BBB','CCC'] ;
    For i := Length(toolbar_list) - 1 DownTo 0 DO
    Begin
        toolbar_list[i] := ttoolbutton.create(Form1) ;
        toolbar_list[i].parent   := toolbar;
        toolbar_list[i].Autosize := True ;
        toolbar_list[i].width    := 100 ;
        toolbar_list[i].caption  := toolbar_list[i].Name ;
    End;
end.

https://i.ibb.co/wZtnbZ3/image-2022-12-22-152109309.png

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: How to Show Caption In Toolbutton

procedure Form1_OnShow (Sender: TObject; Action: string);
  var
toolbar : Ttoolbar ;
toolbar_list:TToolbutton ;
toolbar_list_Name:TStringList;
i : Integer ;
begin
    toolbar_list_Name := TStringList.Create;
    toolbar_list_Name.Add('AAA');
    toolbar_list_Name.Add('BBB');
    toolbar_list_Name.Add('CCC');

    toolbar := Ttoolbar.Create(Form1) ;
    toolbar.Parent := Form1.Panel1 ;
    toolbar.showcaptions := true;
    toolbar.Autosize := True ;



    For i := toolbar_list_Name.Count- 1 DownTo 0 DO
    Begin
        toolbar_list := ttoolbutton.create(Form1) ;
        toolbar_list.parent   := toolbar;
        toolbar_list.Autosize := True ;
        toolbar_list.Height    := 200 ;
        toolbar_list.width    := 200 ;
        toolbar_list.caption  := toolbar_list_Name[i];
    End;

end;

Re: How to Show Caption In Toolbutton

wow...great...
...and how can i intercept the user action when he clicks the button?
For example, if you click on the AAA button it will activate a script, if you click on the BBB button it will activate another script...and so on...Thanks

Re: How to Show Caption In Toolbutton

prahousefamily wrote:

..

How to Show Caption In Toolbutton ?
...

var
    toolbar : Ttoolbar ;
    bn : TToolbutton ;
    bn_caps : array of String ;
    i : Integer ;
begin
    toolbar := Ttoolbar.Create(Form1) ;
    toolbar.Parent := Form1.Panel1 ;
    toolbar.showcaptions := true;
    toolbar.Autosize := True ;
    bn_caps := ['AAA','BBB','CCC','DDDDDDDDDD'] ;
    For i := Length(bn_caps) - 1 DownTo 0 DO
    Begin
        with ttoolbutton.create(Form1) do
        begin
            parent   := toolbar;
            Autosize := True ;
            //width    := 100 ;   // ?
            caption  := bn_caps[i] ;
        end;
    End;
end.

Re: How to Show Caption In Toolbutton

madbit71 wrote:

wow...great...
...and how can i intercept the user action when he clicks the button?
For example, if you click on the AAA button it will activate a script, if you click on the BBB button it will activate another script...and so on...Thanks

procedure AAA;
begin
  ShowMessage('AAA');
end;

procedure BBB;
begin
    ShowMessage('BBB');
end;

procedure CCC;
begin
  ShowMessage('CCC');
end;

procedure BnClick(Sender:TToolButton);
begin
   case Sender.Caption of
       'AAA' : AAA;
       'BBB' : BBB;
       'CCC' : CCC;
   end;
end;

var
    toolbar : Ttoolbar ;
    bn : TToolbutton ;
    bn_caps : array of String ;
    i : Integer ;
begin
    toolbar := Ttoolbar.Create(Form1) ;
    toolbar.Parent := Form1.Panel1 ;
    toolbar.showcaptions := true;
    toolbar.Autosize := True ;
    bn_caps := ['AAA','BBB','CCC'] ;
    For i := Length(bn_caps) - 1 DownTo 0 DO
    Begin
        with ttoolbutton.create(Form1) do
        begin
            parent   := toolbar;
            Autosize := True ;
            caption  := bn_caps[i] ;
            OnClick := @BnClick;
        end;
    End;
end.

Re: How to Show Caption In Toolbutton

great...works perfectly...thanks smile