Hi, I would like to drag the mouse over a form, while the mouse is dragged, 
FPos X and Y values must change in the direction of the move, but the mouse 
cursor must be fixed at the position where the first click was made.


This code does more or less what I want, but has two problems:


1 - The mouse still moves a little.
2 - The values of FPos.X and FPos.Y doesn't change.


What I'm doing wrong?.


Just add a TLabel over a form, and override TForm.OnMouseMove, OnMouseDown and 
OnPaint events.



unit Unit1; 


{$mode objfpc}{$H+}


interface


uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;


type


  { TForm1 }


  TForm1 = class(TForm)
    Label1: TLabel;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
  private
    { private declarations }
  public
    FPos: TPoint;
  end; 


var
  Form1: TForm1; 


implementation


{$R *.lfm}


{ TForm1 }



procedure TForm1.FormPaint(Sender: TObject);
begin
  Label1.Caption := Format('X: %d - Y: %d', [FPos.X, FPos.Y]);
end;


procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ssleft in shift then
  begin
    FPos.X := X;
    FPos.Y := Y;
  end;
end;


procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if ssLeft in shift then
  begin
    Mouse.CursorPos := ClientToScreen(FPos);
    FPos.X := X;
    FPos.Y := Y;
    Invalidate;
  end;
end;


Leonardo.

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to