Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TcxCustomTreeView.GetHitTestInfoAt(Integer,Integer) Method

Determines the elements of the control located under a specified point.

#Declaration

Delphi
function GetHitTestInfoAt(X: Integer; Y: Integer): THitTests;

#Parameters

Name Type
X Integer
Y Integer

#Returns

Type
THitTests

#Remarks

Use the GetHitTestInfoAt method to determine the element of the control located under a specified point. The point is specified by its horizontal and vertical coordinates using X and Y method parameters. Note that coordinates must be set in the control’s client coordinates. Thus, if you have screen coordinates of the point, use the control’s ScreenToClient method to obtain client coordinates.

Generally, the GetHitTestInfoAt method is used to determine the element located under the mouse pointer. For instance, you may need to display information about the element located under the pointer within the status bar. Another example can be invoking the context menu when end-users click node captions. Note that the GetHitTestInfoAt method is most commonly used in conjunction with the GetNodeAt method. The latter returns the node located under the specified point.

The sample code below handles the OnClick event of the tree view control. If the clicked element is a node image, then an overlay image is painted. The overlay image represents a red X. It is applied by setting the OverlayIndex property of the node to a value different from -1. The code uses the GetHitTestInfoAt method to determine whether the mouse pointer is over a node image. The node is obtained using the GetNodeAt method call.

Delphi
procedure TForm1.cxTreeView1Click(Sender: TObject);
var
  MousePos: TPoint;
  Node: TTreeNode;
begin
  MousePos := Mouse.CursorPos;
  MousePos := cxTreeView1.ScreenToClient(MousePos);
  Node := cxTreeView1.GetNodeAt(MousePos.X, MousePos.Y);
  if Node <> nil then
    if htOnIcon in cxTreeView1.GetHitTestInfoAt(MousePos.X, MousePos.Y) then
    begin
      if Node.OverlayIndex = -1 then
        Node.OverlayIndex := 0
      else
        Node.OverlayIndex := -1;
    end;
end;

If this handler for the OnClick event is used, end-users can click node images to show and hide the red X. The result is as follows:

See the ToolTips topic for another example of using the GetHitTestInfoAt method.

See Also