The Delphi Bug List

Entry No.
678
VCL - Win32 - ComCtrls - TTreeView
TTreeView.OnMouseUp coordinates differ depending on mouse button used.
1.02 2.01 3.0 3.01 3.02 4.0 4.01 4.02 4.03 5.0 5.01 6.0 6.01 6.02 Kylix 1.0
N/AAbsentAbsentAbsentAbsentAbsentAbsentAbsentAbsentAbsentAbsentExistsExistsExistsN/A
Description
Reported by Damien Burke; checked by Jordan Russell
TTreeview.OnMouseUp coordinates differ depending on mouse button used.

Reproducible:
Oh yes. Drop a TTreeview on a form, assign some code to the OnMouseUp event as follows:

procedure TForm1.TreeView1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ShowMessage(IntToStr(X)+','+IntToStr(Y));
end;

Run and try a left-click on the tree view followed by a right click *without moving the mouse* in between. Note the entirely different coordinates displayed. Suspect right-clicking is returning screen-based coors whereas left-clicking is (correctly) returning control client area coors.

Cause: ?

Version: D6. Not present in D4. Not present in D5 (D5 actually fails to fire the OnMouseUp event entirely unless you double-right click or move the mouse a little between depressing and releasing the button).

OS: bug apparent in both Windows 2000 SP2 and Win98SE.

Solution / workaround
Check Button parameter for right mouse button and if so, use ScreenToClient to change coors to client ones. Alternatively if OnMouseUp was being used to pop up a context menu, use the OnContextPopup event instead. If OnMouseUp was being used to select an item, set the RightClickSelect property to True instead.
Latest update of this entry: 2002-02-28

Post a comment on this bug


Index page
Delphi Bug List home page
The Delphi Bug Lists are presently maintained by Jordan Russell, who has taken over this task from Reinier Sterkenburg since August 2000.
All feedback is appreciated. See also the feedback section of the Delphi Bug List home page.