delphi 磁性窗体

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

转载自百度空间,技术文档,以便自学

Delphi 磁性窗体

FORM1

unit Unit1;

interface

uses

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

type

TForm1 = class(TForm)

Button1: TButton;

Button2: TButton;

procedure Button1Click(Sender: TObject);

procedure Button2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

uses unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin

form2.Show;

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

close;

end;

end.

下边是测试用的form2

unit Unit2;

interface

uses

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

type

TForm2 = class(TForm)

private

procedure WMWINDOWPOSCHANGING(Var Msg: TWMWINDOWPOSCHANGING);message WM_WINDOWPOSCHANGING;

{ Private declarations }

public

{ Public declarations }

end;

var

Form2: TForm2;

implementation

uses Unit1;

{$R *.dfm}

{ TForm2 }

procedure TForm2.WMWINDOWPOSCHANGING(var Msg: TWMWINDOWPOSCHANGING); var

WorkDound: TRect;

remove : Word;

begin

remove :=50; //可随意设置,是磁性的范围大小。

WorkDound.Left:=form1.left;

WorkDound.Top:=form1.Top;

WorkDound.Right:=form1.left+form1.Width;

WorkDound.Bottom:=form1.Top+form1.Height;

with Msg.WindowPos^ do

begin

if (x+cx

if (x+cx>WorkDound.Left-remove)or((x+cx>WorkDound.Left) and

(x+cx

begin

x:=WorkDound.Left-cx;

end;

if (x>WorkDound.Right-remove) then //右方具有磁性

if (x

(x>WorkDound.Right-remove)) then

begin

x:=WorkDound.Right;

end;

if (y+cy

if (y+cy>WorkDound.Top-remove)or((y+cy>WorkDound.Top) and

(y+cy

begin

y:= WorkDound.Top-cy;

end;

if (y>WorkDound.Bottom-remove) then //下方具有磁性

if (yWorkDound.Bottom-remove)) then

begin

y:= WorkDound.Bottom;

end;

end;

inherited;

end;

end.

相关文档
最新文档