Redigera

Dela via


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)

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

public:
 System::Windows::Forms::TreeViewHitTestInfo ^ HitTest(int x, int y);
public System.Windows.Forms.TreeViewHitTestInfo HitTest (int x, int y);
member this.HitTest : int * int -> System.Windows.Forms.TreeViewHitTestInfo
Public Function HitTest (x As Integer, y As Integer) As TreeViewHitTestInfo

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.

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());
        }
    }
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());
    }
}
Sub treeView1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) 
    Dim info As TreeViewHitTestInfo = treeView1.HitTest(e.X, e.Y)
    Dim hitNode As TreeNode
    If (info.Node IsNot Nothing) Then
        hitNode = info.Node
        MessageBox.Show(hitNode.Level.ToString())
    End If

End Sub

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

HitTest(Point)

Provides node information, given a point.

public:
 System::Windows::Forms::TreeViewHitTestInfo ^ HitTest(System::Drawing::Point pt);
public System.Windows.Forms.TreeViewHitTestInfo HitTest (System.Drawing.Point pt);
member this.HitTest : System.Drawing.Point -> System.Windows.Forms.TreeViewHitTestInfo
Public Function HitTest (pt As Point) As TreeViewHitTestInfo

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