Link to home
Start Free TrialLog in
Avatar of khenr29j
khenr29j

asked on

Using the TToolbar component

Is it possible to add toolbar buttons at run-time? Sample code would be extremely helpful.
Avatar of anilms
anilms

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.

Avatar of khenr29j

ASKER

I would like to add TToolButtons to it, not normal controls. TToolButtons can be made flat-looking, a la Netscape.
ASKER CERTIFIED SOLUTION
Avatar of anilms
anilms

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks!