TreeView::HitTest Method (Int32, Int32)

 

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
)

Parameters

x
Type: System::Int32

The x-coordinate at which to retrieve node information

y
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.

private:
    void InitialTreeView_MouseDown(Object^ sender, MouseEventArgs^ e)
    {
        TreeViewHitTestInfo^ info = initialTreeView->HitTest(e->X, e->Y);
        TreeNode^ hitNode;

        if (info->Node != nullptr)
        {
            hitNode = info->Node;
            MessageBox::Show(hitNode->Level.ToString());
        }
    }

.NET Framework
Available since 2.0
Return to top
Show: