Delphi Mouse Movable Form

  public
    { Public declarations }
    dragging:boolean;
    dx,dy:integer;
  end;

procedure TForm2.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  p:tpoint;
begin
  if button<>mbright then
  begin
    p:=(sender as tcontrol).clienttoscreen(point(x,y));
    dragging:=true;
    dx:=p.x;
    dy:=p.y;
  end;
end;

procedure TForm2.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  nx,ny:integer;
  p:tpoint;
begin
  if dragging then
  begin
    p:=(sender as tcontrol).clienttoscreen(point(x,y));
    nx:=left+p.x-dx;
    ny:=top+p.y-dy;
    dx:=p.x;
    dy:=p.y;
    BoundsRect:=rect(nx,ny,nx+width,ny+height);
  end;
end;

procedure TForm2.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  dragging:=false;
end;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s