请教动态生成BUTTON的移动问题?
各位大家好:
小弟又有问题来了,请大家教教我!我用下面这段代码在表格StringGrid1里每点一次就生成一个按键!可是生成的按键我不知道怎么移动?我想点住BUTTON就能随意移动.请大家教教我.
var Btn:TButton;
PT:TPoint;
begin
GetCursorPos(PT);
Btn:=TButton.Create(Self);
with Btn do
begin
Parent:=Self;
Btn.Caption:= '按键 ';
Width:=50;
height:=20;
Left:=ScreenToClient(PT).X;
Top:=ScreenToClient(PT).Y;
Btn.OnClick:=buttonClickEvent;
//Btn.OnClick:= ButtonClick;
// Btn.OnMouseMove:=ButtonMouseMove;
Show;
end;
end;
[解决办法]
DragKind := dkDock;
DragMode := dmAutomatic;
[解决办法]
这贴分多,再来这里混一把.... ^_^
下面这是演示在Form上动态生成按钮,并可以拖动,供你参考:
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ButtonMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ButtonMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
ReleaseCapture;
TControl(Sender).Perform(WM_SysCommand,$F012,10);
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
With TButton.Create(self) do
begin
Left := X;
Top := Y;
Parent := self;
Caption := Format( '%d,%d ',[X,Y]);
OnMouseMove := ButtonMouseMove;
Show;
end;
end;