Código
É só colar dentro da unit da form.}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
contador:integer;
implementation
{$R *.DFM}
uses stdctrls;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var b:tbutton;
begin
b:=Tbutton.create(self);
b.visible:=false;
b.parent:=self;
b.left:=x;
b.top:=y;
b.name:='Btn'+inttostr(contador);
b.Caption:='Clique-me';
inc(contador);
b.visible:=true;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
contador:=1;
end;
end. //Se quiser associar um evento ao botão é só copiar os procedimento clicou e alterar
//o procedimento mouse down para o que segue.
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var b:tbutton;
begin
b:=Tbutton.create(self);
b.visible:=false;
b.parent:=self;
b.left:=x;
b.top:=y;
b.name:='Btn'+inttostr(contador);
b.Caption:='Clique-me';
inc(contador);
b.visible:=true;
b.onclick:=clicou;
end;
procedure TForm1.clicou(sender: TObject);
begin
ShowMessage('Clicou!!!');
end;
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009