How to add a virtual copy of an image under my drag curso ? lazarus / 9-Editor ---------------------------------------------------------------------- GoDxNero · 2010-06-24 22:40 Code: [Select]procedure TForm1.FormDragDrop(Sender, Source: TObject; X, Y: Integer); begin   if Source is TShape then   begin     TShape(Source).Left := X - Round(TShape(Source).Width / 2);     TShape(Source).Top := Y - Round(TShape(Source).Height / 2);   end; end; procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;   State: TDragState; var Accept: Boolean); begin   Accept := (Source is TShape); end; procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   Shape1.BeginDrag(True) ; end; http://i50.tinypic.com/30a9po9.jpg ---------------------------------------------------------------------- theo · 2010-06-24 22:50 What do you want to achieve? http://catb.org/esr/faqs/smart-questions.html#goal If you just want to move shapes, then I'd use OnMouseDown, OnMouseMove, OnMouseUp to do that. ---------------------------------------------------------------------- GoDxNero · 2010-06-24 23:27 Quote from: theo on June 25, 2010, 12:50:14 amWhat do you want to achieve? http://catb.org/esr/faqs/smart-questions.html#goal If you just want to move shapes, then I'd use OnMouseDown, OnMouseMove, OnMouseUp to do that. can you give me an example of how to get the cursor position ? So I can set the image position on click and move mouse. Edit, btw all my question are stated in the image-links if you didnt see it before. ---------------------------------------------------------------------- theo · 2010-06-25 01:50 Example: You have a TShape on a TForm and create Eventhandlers in the Object-Inspector for: Shape1 (OnMouseDown, OnMouseMove, OnMouseUp), Form1 (OnMouseMove) Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,   ExtCtrls; type   { TForm1 }   TForm1 = class(TForm)     Shape1: TShape;     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);     procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;       Shift: TShiftState; X, Y: Integer);     procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer       );     procedure Shape1MouseUp(Sender: TObject; Button: TMouseButton;       Shift: TShiftState; X, Y: Integer);   private     { private declarations }     FStartPos:TPoint;     fMoving:Boolean;   public     { public declarations }   end; var   Form1: TForm1; implementation { TForm1 } procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   fStartPos:=Point(X,Y);   fMoving:=True; end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,   Y: Integer); begin   Shape1MouseMove(Sender,Shift, X, Y); end; procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,   Y: Integer); begin    if fMoving then    begin      Shape1.Left:=ScreenToClient(Mouse.CursorPos).X-FStartPos.X;      Shape1.Top:=ScreenToClient(Mouse.CursorPos).Y-FStartPos.Y;    end; end; procedure TForm1.Shape1MouseUp(Sender: TObject; Button: TMouseButton;   Shift: TShiftState; X, Y: Integer); begin   fMoving:=False; end; initialization   {$I unit1.lrs} end. ---------------------------------------------------------------------- mas steindorff · 2010-06-28 13:08 nice code snippet theo.  I ended up playing with this for hours moving shapes, images, and shadows while the mouse button was pressed.  Maybe this would be a good example to drop on the wiki or the new Lazarus support page. ---------------------------------------------------------------------- theo · 2010-06-28 14:13 Quote from: mas steindorff on June 28, 2010, 03:08:07 pmMaybe this would be a good example to drop on the wiki or the new Lazarus support page. Feel free to add it. I for one would choose a different approach, but wanted to keep it simple for this thread. I would define some "TPaintObjects" (mainly areas and paint types) and would draw everything on a TCustomControl descendant Canvas in an overridden procedure Paint by myself. This means holding a list of PaintObjects and check by looping through the list, if the mouseclick or whatever is on any of them. But using TShape is OK as well if it fulfills all the needs. ---------------------------------------------------------------------- JuhaManninen · 2010-06-28 21:05 Quote from: theo on June 28, 2010, 04:13:03 pmI would define some "TPaintObjects" (mainly areas and paint types) and would draw everything on a TCustomControl descendant Canvas in an overridden procedure Paint by myself. This means holding a list of PaintObjects and check by looping through the list, if the mouseclick or whatever is on any of them. Is there source available for such more advanced painting program for Lazarus? Juha