Page 1 of 1

Mouse handling in TTree

Posted: Mon Nov 25, 2024 7:06 pm
by 16498776
Hello!

In the TTree component I set the ScrollMouseButton to mbRight. If i right click on the TTree and drag it moves the entire workarea as expected.
I also have an OnClickShape event where i check if it's a mbRight button pressed and if that's the case i show a popup menu.
After selecting a function in the popup menu the TTree is someway still hooked to the mouse, so when i move the mouse (without pressing any mouse button) the entire workare moves as if I was "Right mouse button" moving.

Any idea how to prevent this?

I want the "right button move" function to work as usual, but when right clicking a TTreeNodeShape there should be no movement.

Best regards, Mikael

Re: Mouse handling in TTree

Posted: Thu Dec 19, 2024 4:40 pm
by 16593767
Hi Mikael

Maybe you could use TTree.CancelMouse in the MouseMove event to stop the "sticky mouse".

If you add a state variable "mbRightIsPressed" to your form and set it in the Tree.OnMouseDown event handler:

Code: Select all

  mbRightIsPressed := (Button = TMouseButton.mbRight);
and reset the variable in the Tree.OnMouseUp event:

Code: Select all

  mbRightIsPressed := False;
Then you could test if any mousebutton(s) are pressed in the Tree.OnMouseMove event, and if nothing is pressed then you use CancelMouse like this:

Code: Select all

if (not mbRightIsPressed) then
  Tree1.CancelMouse := True;