[Lazarus] (no subject)

Leonardo Rame l.rame at griensu.com
Sun Jul 31 00:15:07 CEST 2011


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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110730/b173b2c0/attachment-0002.html>


More information about the Lazarus mailing list