很简单,首先写一个事件处理函数,然后在创建的时候连接进去就行了啊。
看下面的代码。
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OnEditMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.OnEditMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbRight then
begin
ShowMessage((Sender as TEdit).Text);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
With TEdit.Create(Application) do
begin
Parent := Form1;
Left := 10;
Top := 10;
OnMouseDown := OnEditMouseDown; <---连接事件处理程序
Show;
end;
end;