当鼠标单击窗口的时候,我们自动的创建一个按钮,代码实现如下:
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
StdCtrls;
procedure TForm1.FormMouseDown(
Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Btn: TButton;
begin
Btn := TButton.Create (Self);
Btn.Parent := Self;
Btn.Left := X;
Btn.Top := Y;
Btn.Width := Btn.Width + 50;
Btn.Caption := Format (‘Button at %d, %d‘, [X, Y]);
end;
end.
时间: 2024-08-09 02:21:06