随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

问题来源: http://www.cnblogs.com/del/archive/2008/12/20/985931.html#1408193

本例中的 Form2 所在 Unit2 中没有任何代码, 以下是 Unit1 中的代码:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormShow(Sender: TObject);
  protected
    procedure WMMove(var Message: TWMMove); message WM_MOVE;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

uses Unit2;

var a,b: Integer;

procedure TForm1.FormShow(Sender: TObject);
begin
  Form2.Show;
  Form2.Left := Left;
  Form2.Top := Top + Height;
  a := Form2.Left - Left;
  b := Form2.Top - Top;
end;

procedure TForm1.WMMove(var Message: TWMMove);
begin
  if Assigned(Form2) then
  begin
    Form2.Left := Left + a;
    Form2.Top := Top + b;
  end;
  inherited;
end;

end.

posted on 2008-12-20 17:47  万一  阅读(...)  评论(...编辑  收藏