频道分类

delphi 实现窗体随着鼠标移动

作者:admin 来源: 日期:2018/3/5 12:54:47 人气: 标签:

 
private  //窗体移动;
OldPos,NewPos:TPoint;
bMove:Boolean;
 
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bMove:=True;
OldPos:=ClientToScreen(Point(X,Y));
end;
 
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if not bMove then Exit;
NewPos:=ClientToScreen(Point(X,Y));
Left:=Left+NewPos.X-OldPos.X;
Top:=Top+NewPos.Y-OldPos.Y;
OldPos:=NewPos;
end;
 
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bMove:=False;
end;