TreeView.HitTest Method (Int32, Int32)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Provides node information, given x- and y-coordinates.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public TreeViewHitTestInfo HitTest(
	int x,
	int y


Type: System.Int32

The x-coordinate at which to retrieve node information

Type: System.Int32

The y-coordinate at which to retrieve node information.

Return Value

Type: System.Windows.Forms.TreeViewHitTestInfo

The node information.

Use this method to determine whether a set of x- and y-coordinates is located in a TreeNode and where within the node the point is located, such as on the label or image area.

The following code example code demonstrates how to use the Level, Node, and HitTest members. To run this example, create a Windows Form that contains a TreeView named treeView1 and populate it with several levels of nodes. Paste the following code into the form and associate the MouseDown event of treeView1 with the treeView1_MouseDown method in this example.

void treeView1_MouseDown(object sender, MouseEventArgs e)
    TreeViewHitTestInfo info = treeView1.HitTest(e.X, e.Y);
    TreeNode hitNode;
    if (info.Node != null) {
        hitNode = info.Node;

.NET Framework
Available since 2.0
Return to top