欢迎来到天天文库
浏览记录
ID:44890241
大小:28.00 KB
页数:3页
时间:2019-11-01
《delphi 磁性窗体》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、转载自百度空间,技术文档,以便自学Delphi磁性窗体FORM1unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm) Button1:TButton; Button2:TButton; procedureButton1Click(Sender:TObject); procedureButt
2、on2Click(Sender:TObject);private {Privatedeclarations}public {Publicdeclarations}end;varForm1:TForm1;implementationusesunit2;{$R*.dfm}procedureTForm1.Button1Click(Sender:TObject);beginform2.Show;end;procedureTForm1.Button2Click(Sender:TObject);beginclos
3、e;end;end.下边是测试用的form2unitUnit2;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs;typeTForm2=class(TForm)privateprocedureWMWINDOWPOSCHANGING(VarMsg:TWMWINDOWPOSCHANGING);messageWM_WINDOWPOSCHANGING; {Privatedeclaratio
4、ns}public {Publicdeclarations}end;varForm2:TForm2;implementationusesUnit1;{$R*.dfm}{TForm2}procedureTForm2.WMWINDOWPOSCHANGING(varMsg:TWMWINDOWPOSCHANGING);varWorkDound:TRect;remove:Word;beginremove:=50;//可随意设置,是磁性的范围大小。WorkDound.Left:=form1.left;WorkDoun
5、d.Top:=form1.Top;WorkDound.Right:=form1.left+form1.Width;WorkDound.Bottom:=form1.Top+form1.Height;withMsg.WindowPos^dobegin if(x+cxWorkDound.Left-remove)or((x+cx>WorkDound.Left)and(x+cx6、ove))then begin x:=WorkDound.Left-cx; end; if(x>WorkDound.Right-remove)then //右方具有磁性 if(xWorkDound.Right-remove))then begin x:=WorkDound.Right; end; if(y+cy7、WorkDound.Top-remove)or((y+cy>WorkDound.Top)and(y+cyWorkDound.Bottom-remove)then //下方具有磁性 if(y8、ove)or((yWorkDound.Bottom-remove))then begin y:=WorkDound.Bottom; end;end;inherited;end;end.
6、ove))then begin x:=WorkDound.Left-cx; end; if(x>WorkDound.Right-remove)then //右方具有磁性 if(xWorkDound.Right-remove))then begin x:=WorkDound.Right; end; if(y+cy
7、WorkDound.Top-remove)or((y+cy>WorkDound.Top)and(y+cyWorkDound.Bottom-remove)then //下方具有磁性 if(y8、ove)or((yWorkDound.Bottom-remove))then begin y:=WorkDound.Bottom; end;end;inherited;end;end.
8、ove)or((yWorkDound.Bottom-remove))then begin y:=WorkDound.Bottom; end;end;inherited;end;end.
此文档下载收益归作者所有