1
votes

I have a ScrollBox in which I have a GridPanel in which I have Buttons. I set DragMode to dmAutomatic for all buttons so I can move the buttons around (drag and drop).

But I have a problem: because the GridPanel is larger than the ScrollBox, the ScrollBox has the vertical scrollbar visible. I want to make the ScrollBar to automatically scroll down so I can drop a bottom from the visible (top) rows into the inaccessible rows at the bottom (this is typical behavior for all Windows programs, right?)

I have simple code that is doing this: In MouseMove I detect when the mouse is getting close to the bottom of the ScrollBox and I adjust ScrollBox.VertScrollBa.Position to scroll down. This works ONLY if I am NOT in "drag and drop" mode (if I am not dragging a button).

If I start a drag and drop operation NO mouse events are fired.

What can I do to receive MouseMove event even if I am in "drag and drop" mode?
A solution would be not to use dmAutomatic and implement my own drag and drop alternative (based on mousedown, mousemove, mouseup). Is these a quicker fix?

1
If I remember correctly a TDragObject will receive and handle the mouse messages during Drag&Drop. But you should then get e.g. DragOver events instead.nil
@nil - I think I get the idea: "move the code from MouseMove to DragOver". I will try it. thanks!Z80
Maybe, if it's true that you receive MouseMove when not dragging and DragOver when dragging.nil
@nil - it works. can you post your comment as an answer so I can accept it? 1.5 million thanks.Z80
"What can I do to receive MouseMove event even if I am in "drag and drop" mode?" - Nothing... you can't. See documentation for SetCapture on MSDN for explanation. Called from TDragObject.Capture.Sertac Akyuz

1 Answers

4
votes

During drag-and-drop operations the VCL will create a TDragObject to manage said drag-and-drop operation. This TDragObject - or a derived class - will start receiving and handling mouse events as long as dragging lasts. In turn, it will generate drag-and-drop specific events like OnDragOver and OnDragDrop which can be handled by - potential target - controls under current mouse position.

This will allow you to handle OnMouseMove whenever no drag-and-drop is happening. In addition handle OnDragOver in a similar way to catch mouse movements when currently dragging.