Forum > LCL

How to know when dragging actually occurs when using BeginDrag(False)?

(1/1)

Aistis:
Today I was playing around with drag and drop controls for the first time. But I now have a question. Is there a way to know when a control is actually being dragged when using BeginDrag(False)?

For example, when I'm using BeginDrag(False, 5) (with DragMode := dmManual), a single stationary mouse press instantly calls the OnStartDrag and sets the TControl.Dragging to True despite my mouse position never breaking that 5 pixel threshold at which the dragging logic actually kicks in.

With the procedure signature being BeginDrag(Immediate: boolean; Threshold: integer) I naturally assumed that TControl.Dragging would be set to True only after exceeding the Threshold with the OnStartDrag event being called alongside it.

Is this the way it is supposed to work?

Edit: forgot to mention that I'm on Linux Mint. Haven't tested this on Windows yet.

jamie:
I don't have Delphi in front of me atm, however, I Think this could be a bug because it makes no sense.

Reading online docs from the other guy leads me to believe that this should only report dragging as true when the threshold is reached.

Jamie the mad man!

Aistis:
Can't believe it took me this long to make a simple working example O:-)

With DragMode := dmManual set, OnStartDrag() starts the moment the control is clicked and not yet dragged despite having a BeginDrag(False, 5) in the control's OnMouseDown() event. Seeing how the BeginDrag signature is BeginDrag(Immediate: boolean; Threshold: integer) I assumed that the dragging should start after the threshold is hit (and so should OnStartDrag() be called after the threshold is hit).

Is there a way to know when the dragging actually occurs after escaping the threshold given to BeginDrag(False, 5)? I'm attaching the demo project and a GIF.

Aistis:
Changing the ElemOnMouseDown from my attached project above and adding two new events makes it easy to get the behaviour that I want/expect (code bellow). But this kind of makes the whole BeginDrag(False, 5) moot, since I instead have to call BeginDrag(True) once I make sure the 5 pixel threshold is hit.

I'm attaching the demo project with these changes.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TTest.ElemOnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,  Y: Integer);begin  FStartingPoint := Point(X, Y);  FTrigger.OnMouseMove := @ElemOnMouseMove;  FTrigger.OnMouseUp := @ElemOnMouseUp;end; procedure TTest.ElemOnMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,  Y: Integer);begin  FTrigger.OnMouseMove := nil;    FTrigger.OnMouseUp := nil;end; procedure TTest.ElemOnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin  if FStartingPoint.Distance(Point(X, Y)) >= 5 then  begin    FTrigger.OnMouseMove := nil;        FTrigger.OnMouseUp := nil;    FTrigger.BeginDrag(True);  end;end;
TControl.BeginDrag docs also mention how the set threshold is "Minimum mouse movement before delayed dragging starts". But as I said before, both OnStartDrag is called and Dragging is set to True when the TControl is pressed, not when the dragging actually starts when using BeginDrag(False).

Unless the word delayed in the docs means that the drag does starts from a mouse press but the process of dragging itself is delayed. But then again, that makes OnStartDrag() and Dragging; basically useless when using BeginDrag(False);.

Navigation

[0] Message Index

Go to full version