<div>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.</div>
<div><br />
</div>
<div>This code does more or less what I want, but has two problems:</div>
<div><br />
</div>
<div>1 - The mouse still moves a little.</div>
<div>2 - The values of FPos.X and FPos.Y doesn't change.</div>
<div><br />
</div>
<div>What I'm doing wrong?.</div>
<div><br />
</div>
<div>Just add a TLabel over a form, and override TForm.OnMouseMove, OnMouseDown and OnPaint events.</div>
<div><br />
</div>
<div>
<div>unit Unit1; </div>
<div><br />
</div>
<div>{$mode objfpc}{$H+}</div>
<div><br />
</div>
<div>interface</div>
<div><br />
</div>
<div>uses</div>
<div> Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;</div>
<div><br />
</div>
<div>type</div>
<div><br />
</div>
<div> { TForm1 }</div>
<div><br />
</div>
<div> TForm1 = class(TForm)</div>
<div> Label1: TLabel;</div>
<div> procedure FormMouseDown(Sender: TObject; Button: TMouseButton;</div>
<div> Shift: TShiftState; X, Y: Integer);</div>
<div> procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);</div>
<div> procedure FormPaint(Sender: TObject);</div>
<div> private</div>
<div> { private declarations }</div>
<div> public</div>
<div> FPos: TPoint;</div>
<div> end; </div>
<div><br />
</div>
<div>var</div>
<div> Form1: TForm1; </div>
<div><br />
</div>
<div>implementation</div>
<div><br />
</div>
<div>{$R *.lfm}</div>
<div><br />
</div>
<div>{ TForm1 }</div>
</div>
<div><br />
</div>
<div>procedure TForm1.FormPaint(Sender: TObject);</div>
<div>begin</div>
<div> Label1.Caption := Format('X: %d - Y: %d', [FPos.X, FPos.Y]);</div>
<div>end;</div>
<div><br />
</div>
<div>procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;</div>
<div> Shift: TShiftState; X, Y: Integer);</div>
<div>begin</div>
<div> if ssleft in shift then</div>
<div> begin</div>
<div> FPos.X := X;</div>
<div> FPos.Y := Y;</div>
<div> end;</div>
<div>end;</div>
<div><br />
</div>
<div>procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,</div>
<div> Y: Integer);</div>
<div>begin</div>
<div> if ssLeft in shift then</div>
<div> begin</div>
<div> Mouse.CursorPos := ClientToScreen(FPos);</div>
<div> FPos.X := X;</div>
<div> FPos.Y := Y;</div>
<div> Invalidate;</div>
<div> end;</div>
<div>end;</div>
<div><br />
</div>
<div>Leonardo.</div>