• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Using the TToolbar component

Is it possible to add toolbar buttons at run-time? Sample code would be extremely helpful.
0
khenr29j
Asked:
khenr29j
  • 2
  • 2
1 Solution
 
anilmsCommented:
Yes, it is possible to add buttons at run time. Do the following:

1. Create an application. Drop a button onto the form. Drop a TToolbar also onto the form.

2. In the variabled section, add ButtonNew as a TButton variable.

3. For Button1 click event, add the event hadnling code.

4. The whole program should be as follows :

----------------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ToolWin, ComCtrls;

type
  TForm1 = class(TForm)
    ToolBar1: TToolBar;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ButtonNew:TButton;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
      {Creating a New Button}
      ButtonNew := TButton.Create(ToolBar1);
      {Setting the parent to the ToolBar}
      ButtonNew.Parent := ToolBar1;
end;

end.

0
 
khenr29jAuthor Commented:
I would like to add TToolButtons to it, not normal controls. TToolButtons can be made flat-looking, a la Netscape.
0
 
anilmsCommented:
Instead of the TButton component, you can use the TSpeedButton component and set the Flat property to true on those buttons. This will work well.
0
 
khenr29jAuthor Commented:
Thanks!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now