这个应该十分容易实现。实际起作用的代码应该只有两行。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure MovePanel(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
end;
TAnimateMove = class(TAnimate)
published
property OnMouseDown;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function GetPanel(aControl:TControl):TPanel;
var pal:TControl;
begin
while not( (pal= nil) or (pal is TPanel) ) do
pal := pal.Parent;
Result := pal as TPanel;
end;
procedure TForm1.Button1Click(Sender: TObject);
var palDynamic:TPanel;
begin
palDynamic := TPanel.Create(Self);
with palDynamic do
begin
Parent := Self;
OnMouseDown := MovePanel;
end;
with TLabel.Create(self) do
begin
Parent := palDynamic;
Caption := '动态创建示例';
Align := alTop;
Alignment:= taCenter;
OnMouseDown:=MovePanel;
end;
with TAnimateMove.Create(Self) do
begin
Parent := palDynamic;
Align := alClient;
CommonAVI := aviFindComputer;
Active :=True;
OnMouseDown := MovePanel;
end;
end;
procedure TForm1.MovePanel(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var palDynamic:TPanel;
begin
palDynamic := GetPanel(Sender as TControl);
if(palDynamic = nil) then exit;
ReleaseCapture;
palDynamic.Perform(WM_SYSCOMMAND,$F012,0);
end;
end.