控件? 你是想把form封装成一个控件?
给他一个onmove事件,再事件里调用其他窗体的移动
我的测试例子:
{unit1是form控件
unit2是主窗体,生成Tform1的实例
unit3是始终在最上面的跟随Tform1实例移动的窗体}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TFrmMove=procedure(Sender:TObject;IncX,IncY:integer) of Object;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
ox,oy:integer;
FOnMove:TFrmMove;
procedure WMMove(var Message: TWMMove); message WM_MOVE;
public
{ Public declarations }
property OnMove:TFrmMove read FOnMove write FOnMove;
end;
implementation
{$R *.dfm}
procedure TForm1.WMMove(var Message: TWMMove);
begin
inherited;
if assigned(FOnMove) then
FOnMove(self,message.XPos-ox,message.YPos-oy);
ox:=message.XPos;
oy:=message.YPos;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ox:=Left;
oy:=Top;
end;
end.
//-------------------------------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure FrmDblClick(Sender: TObject);
procedure frmmove(Sender:TObject;IncX,IncY:integer);
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
uses unit1,unit3;
{$R *.dfm}
procedure TForm2.frmmove(Sender:TObject;IncX,IncY:integer);
begin
if form3.Showing then
form3.SetBounds(form3.Left+incx,form3.Top+incy,form3.Width,form3.Height);
end;
procedure TForm2.Button1Click(Sender: TObject);
var
frm:tform1;
begin
frm:=tform1.Create(self);
frm.OnMove:=frmmove;
frm.OnDblClick:=FrmDblClick;
frm.Show;
end;
procedure TForm2.FrmDblClick(Sender: TObject);
begin
form3.Show;
end;
end.
//-------------------------------------------------------
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm3 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormCreate(Sender: TObject);
begin
self.FormStyle:=fsStayOnTop;
end;
end.