当前位置:首页 > 网络编程 > 软件语言 > DELPHI > 制作可移动的窗体的MovePanel控件

制作可移动的窗体的MovePanel控件

点击次数:49 次 发布日期:2008-11-09 08:39:54 作者:源代码网
源代码网推荐
广告载入中
  使用Winamp是有个EasyMove的功能,也就是不在标题栏上拖动鼠标就能移动窗体,虽然EasyMove功能很好实现,可还不如做个控件一劳永逸,另外这个控件还有一个更有用的功能,呆会儿就能见到。我们先看看如何实现它吧!
源代码网推荐
源代码网推荐 ---- 建立一个空的Unit,把以下代码Copy进去,再把它添加到Delphi的控件库里,这样MovePanel控件就做好了。
源代码网推荐
源代码网推荐 unit MovePanel;
源代码网推荐 interface
源代码网推荐 uses
源代码网推荐 Windows, Classes, Controls,ExtCtrls;
源代码网推荐 type
源代码网推荐 TMovePanel = class(TPanel) //这个控件是继承Tpanel类的
源代码网推荐 private
源代码网推荐 PrePoint:TPoint;
源代码网推荐 Down:Boolean;
源代码网推荐 { Private declarations }
源代码网推荐 protected
源代码网推荐 { Protected declarations }
源代码网推荐 public
源代码网推荐 constructor Create(AOwner:TComponent);
源代码网推荐 override;
源代码网推荐 //重载鼠标事件,抢先处理消息
源代码网推荐 procedure MouseDown(Button: TMouseButton;
源代码网推荐 Shift: TShiftState; X, Y: Integer);override;
源代码网推荐 procedure MouseUp(Button: TMouseButton;
源代码网推荐 Shift: TShiftState; X, Y: Integer);override;
源代码网推荐 procedure MouseMove(Shift: TShiftState;
源代码网推荐 X, Y: Integer);override;
源代码网推荐 { Public declarations }

软件开发网 www.mscto.com


源代码网推荐 published
源代码网推荐 { Published declarations }
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure Register;
源代码网推荐
源代码网推荐 implementation
源代码网推荐
源代码网推荐 constructor TMovePanel.Create(AOwner:TComponent);
源代码网推荐 begin
源代码网推荐 inherited Create(AOwner); //继承父类的Create方法
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure TMovePanel.MouseDown(Button:
源代码网推荐 TMouseButton; Shift: TShiftState; X, Y: Integer);
源代码网推荐 begin
源代码网推荐 if (Button=MBLeft) then
源代码网推荐 begin
源代码网推荐 Down:=true;
源代码网推荐 GetCursorPos(PrePoint);
源代码网推荐 end;
源代码网推荐 //如果方法已存在,就触发相应事件去调用它,
源代码网推荐 若不加此语句会造成访存异常
源代码网推荐 if assigned(OnMouseDown) then
源代码网推荐 OnMouseDown(self,Button,shift,x,y);
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure TMovePanel.MouseUp(Button:
源代码网推荐 TMouseButton; Shift: TShiftState; X, Y: Integer);
源代码网推荐 begin
源代码网推荐 if (Button=MBLeft) and Down then
源代码网推荐 Down:=False;
源代码网推荐 if assigned(OnMouseUp) then
源代码网推荐 OnMouseUp(Self,Button,shift,X,y);
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure TMovePanel.MouseMove(Shift:
源代码网推荐 TShiftState; X, Y: Integer);
源代码网推荐 Var
源代码网推荐 NowPoint:TPoint;
源代码网推荐 begin
源代码网推荐 if down then
源代码网推荐 begin
源代码网推荐 GetCursorPos(nowPoint);
源代码网推荐 //self.Parent在Form中就是MovePanel所在的窗体,
源代码网推荐 或是MovePanel所在的容器像Panel
源代码网推荐 self.Parent.Left:=self.Parent.left
源代码网推荐 NowPoint.x-PrePoint.x;
源代码网推荐 self.parent.Top:=self.Parent.Top
源代码网推荐 NowPoint.y-PrePoint.y;
源代码网推荐 PrePoint:=NowPoint;
源代码网推荐 end;
源代码网推荐 if Assigned(OnMouseMove) then
源代码网推荐 OnMouseMove(self,Shift,X,y);
源代码网推荐 end;
源代码网推荐
源代码网推荐 procedure Register;
源代码网推荐 begin
源代码网推荐 RegisterComponents("Md3", [TMovePanel]);
源代码网推荐 end;
源代码网推荐
源代码网推荐 end.
源代码网推荐
源代码网推荐   接下来,看看怎么用它吧。
源代码网推荐 ----用法一:拖一个Form下来,加上我们的MovePanel,Align属性设为alClient,运行一下,移动窗体的效果还不错吧!想取消此功能,把MovePanel的Enabled属性设为False即可,简单吧!
源代码网推荐
源代码网推荐 ----用法二:拖一个Form下来,加上普通的Panel,调整好大小,再在Panel上加上我们的MovePanel, Align属性设为alClient,运行一下,这一次在我们拖动MovePanel时不是窗体在移动,而是Panel和MovePanel一起在窗体上移动,如果我们再把其他的控件放在MovePanel上,就成了可以在窗体上任意移动的控件了,就这么简单! 软件开发网 www.mscto.com


源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华