TreeView.HitTest Method

Definition

Provides node information, given a point.

Overloads

HitTest(Int32, Int32)

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

HitTest(Point)

Provides node information, given a point.

HitTest(Int32, Int32)

Source:
TreeView.cs
Source:
TreeView.cs
Source:
TreeView.cs

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

C#
public System.Windows.Forms.TreeViewHitTestInfo HitTest(int x, int y);

Parameters

x
Int32

The x-coordinate at which to retrieve node information.

y
Int32

The y-coordinate at which to retrieve node information.

Returns

The node information.

Examples

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.

C#
void treeView1_MouseDown(object sender, MouseEventArgs e)
{
    TreeViewHitTestInfo info = treeView1.HitTest(e.X, e.Y);
    TreeNode hitNode;
    if (info.Node != null) {
        hitNode = info.Node;
        MessageBox.Show(hitNode.Level.ToString());
    }
}

Remarks

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.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

HitTest(Point)

Source:
TreeView.cs
Source:
TreeView.cs
Source:
TreeView.cs

Provides node information, given a point.

C#
public System.Windows.Forms.TreeViewHitTestInfo HitTest(System.Drawing.Point pt);

Parameters

pt
Point

The Point at which to retrieve node information.

Returns

The node information.

Remarks

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

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9