[ask] how to drag TEdit when runtime? lazarus / 13-General ---------------------------------------------------------------------- fox · 2006-07-21 02:59 I have a question, how to make the component such as TEdit can be moved with mouse when runtime? I want to make the component move like when we are design form (we can drag the component at the spesific position). Help me please. ---------------------------------------------------------------------- Marc · 2006-07-21 08:33 in the onmousedown handler, set a boolean that you are dragging the control, and store the current mousepos. in the onmousemove handler, check for that boolean, calcualte the mouse offset and reposition the control in the onmouseup handler reset the boolen. ---------------------------------------------------------------------- fox · 2006-07-21 15:33 Quote from: "Marc"in the onmousedown handler, set a boolean that you are dragging the control, and store the current mousepos. in the onmousemove handler, check for that boolean, calcualte the mouse offset and reposition the control in the onmouseup handler reset the boolen. Bro, can you give me an example by code? I have tried but sometime the component move a little eventhough you move the pointer significanly. Thanx.... ---------------------------------------------------------------------- Marc · 2006-07-24 14:52 you may have to turn Capture mouse on. ---------------------------------------------------------------------- JanH · 2006-07-26 13:31 Quote from: "fox"Quote from: "Marc"in the onmousedown handler, set a boolean that you are dragging the control, and store the current mousepos. in the onmousemove handler, check for that boolean, calcualte the mouse offset and reposition the control in the onmouseup handler reset the boolen. Bro, can you give me an example by code? I have tried but sometime the component move a little eventhough you move the pointer significanly. Thanx.... Code: [Select]   var fMouseDown: Boolean;       fMousePoint: TPoint; procedure TForm1.EditMouseDown(Sender, Button, Shift, X, Y); begin   fMouseDown := true;   fMousePoint.x := x;   fMousePoint.y := y; end; procedure TForm1.EditMouseUp(Sender, Button, Shift, X, Y); begin   fMouseDown := false; end; procedure TForm1.EditMouseMove(Sender, Button, Shift, X, Y); begin   if fMouseDown then begin     Edit.Left := Edit.Left-( fMousePoint.x-X );     Edit.Top := Edit.Top-( fMousePoint.y-Y );   end; end; is working ;-) ---------------------------------------------------------------------- Marc · 2006-07-27 09:47 I guess the last EditMouseDown should be EditMouseMove ---------------------------------------------------------------------- d_fly · 2007-04-21 17:08 :? Well this method works (i  mean it solved my problem to move a shape with mouse pressing, tks)... but i am reading a ebook about delphi ("delphi 7 DevelopersGuide")  where it states that if u turn drag mode (propertie of an objetct) to automatic the object should move with the mouse while holding down it. Why doesn't it work? And another question what does the anchors propertie stand for? even when their true i still can move the obect changing the paramater object.left/object.top. tks ---------------------------------------------------------------------- Marc · 2007-04-23 09:08 When you turn on dragging in delphi, it only changes the cursor to indicate you are dragging something. IIRC, the object isself isn't moved. (and if so, it is not impeemented yet) ---------------------------------------------------------------------- d_fly · 2007-04-24 23:09 ok i see... my mistake then... i got the wrong idea by the book, but anyway could be a good porperty to add to lazarus with automatic and manual modes for user to set.