TreeView.HitTest 方法

定义

提供给定位置的节点信息。Provides node information, given a point.

重载

HitTest(Int32, Int32)

在给定 x 和 y 坐标的情况下,提供节点信息。Provides node information, given x- and y-coordinates.

HitTest(Point)

提供给定位置的节点信息。Provides node information, given a point.

HitTest(Int32, Int32)

在给定 x 和 y 坐标的情况下,提供节点信息。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

参数

x
Int32

在其中检索节点信息的 x 坐标。The x-coordinate at which to retrieve node information

y
Int32

在其中检索节点信息的 y 坐标。The y-coordinate at which to retrieve node information.

返回

TreeViewHitTestInfo

节点信息。The node information.

示例

下面的代码示例演示如何使用 LevelNodeHitTest 成员。The following code example code demonstrates how to use the Level, Node, and HitTest members. 若要运行此示例,请创建一个包含命名的 Windows 窗体, TreeView treeView1 并使用多个级别的节点填充该窗体。To run this example, create a Windows Form that contains a TreeView named treeView1 and populate it with several levels of nodes. 将以下代码粘贴到窗体中,并将的 MouseDown 事件 treeView1treeView1_MouseDown 此示例中的方法相关联。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

注解

使用此方法来确定一组 x 坐标和 y 坐标是否位于 TreeNode 该点所在的节点内以及该点所在的节点内(如标签或图像区域)。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.

适用于

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

参数

pt
Point

在其中检索节点信息的 PointThe Point at which to retrieve node information.

返回

TreeViewHitTestInfo

节点信息。The node information.

注解

使用此方法来确定某个点是否位于该点所在 TreeNode 的节点中以及该点所在的节点内(如标签或图像区域)。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.

适用于