TreeView.GetNodeAt TreeView.GetNodeAt TreeView.GetNodeAt TreeView.GetNodeAt Method

정의

지정된 위치에 있는 트리 노드를 검색합니다.Retrieves the tree node that is at the specified location.

오버로드

GetNodeAt(Point) GetNodeAt(Point) GetNodeAt(Point) GetNodeAt(Point)

지정된 지점에 있는 트리 노드를 검색합니다.Retrieves the tree node that is at the specified point.

GetNodeAt(Int32, Int32) GetNodeAt(Int32, Int32) GetNodeAt(Int32, Int32) GetNodeAt(Int32, Int32)

지정된 좌표의 지점에서 트리 노드를 검색합니다.Retrieves the tree node at the point with the specified coordinates.

GetNodeAt(Point) GetNodeAt(Point) GetNodeAt(Point) GetNodeAt(Point)

지정된 지점에 있는 트리 노드를 검색합니다.Retrieves the tree node that is at the specified point.

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

매개 변수

pt
Point Point Point Point

Point 를 평가 하 여 노드를 검색 합니다.The Point to evaluate and retrieve the node from.

반환

합니다 TreeNode 트리 뷰 (클라이언트) 좌표에서 지정 된 위치의 또는 null 해당 위치에 노드가 없는 경우.The TreeNode at the specified point, in tree view (client) coordinates, or null if there is no node at that location.

설명

전달할 수 있습니다는 MouseEventArgs.XMouseEventArgs.Y 좌표가 합니다 MouseDown 이벤트를 XY 새 값 Point.You can pass the MouseEventArgs.X and MouseEventArgs.Y coordinates of the MouseDown event as the X and Y values of a new Point.

추가 정보

GetNodeAt(Int32, Int32) GetNodeAt(Int32, Int32) GetNodeAt(Int32, Int32) GetNodeAt(Int32, Int32)

지정된 좌표의 지점에서 트리 노드를 검색합니다.Retrieves the tree node at the point with the specified coordinates.

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

매개 변수

x
Int32 Int32 Int32 Int32

X 평가 하 고 노드를 검색할 위치입니다.The X position to evaluate and retrieve the node from.

y
Int32 Int32 Int32 Int32

Y 평가 하 고 노드를 검색할 위치입니다.The Y position to evaluate and retrieve the node from.

반환

합니다 TreeNode 트리 뷰 (클라이언트) 좌표에서 지정된 된 위치에 나 null 해당 위치에 노드가 없는 경우.The TreeNode at the specified location, in tree view (client) coordinates, or null if there is no node at that location.

예제

다음 코드 예제에서는 사용자가 사용 하 여 루트가 아닌 트리 노드를 편집할 수 있습니다는 ContextMenu합니다.The following code example lets the user edit nonroot tree nodes by using a ContextMenu. 마우스를 마우스 오른쪽 단추로 클릭할 때 합니다 TreeNode 이때 위치가 결정 하 고 라는 변수에 저장 mySelectedNode합니다.When the user right clicks the mouse, the TreeNode at that position is determined and stored in a variable named mySelectedNode. 루트가 아닌 트리 노드를 선택 하는 경우 노드 레이블을 편집할 수 있도록 편집 가능한 상태에 배치 됩니다.If a nonroot tree node was selected, it is put into an editable state, which allows the user to edit the node label. 사용자가 트리 노드 레이블의 편집을 중지 한 후 새 레이블 텍스트를 계산 되어 저장 됩니다.After the user stops editing the tree node label, the new label text is evaluated and saved. 예를 들어 여러 문자 레이블 텍스트에 유효한 간주 됩니다.For this example, several characters are considered not valid in the label text. 레이블 문자열에 잘못 된 문자 중 하나 또는 문자열이 비어 사용자 오류 알림이 전송 되 고 이전 텍스트에 레이블을 반환 됩니다.If one of the invalid characters is in the label string, or the string is empty, the user is notified of the error and the label is returned to its previous text.

   /* Get the tree node under the mouse pointer and 
      save it in the mySelectedNode variable. */
private:
   void treeView1_MouseDown( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
   {
      mySelectedNode = treeView1->GetNodeAt( e->X, e->Y );
   }

   void menuItem1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      if ( mySelectedNode != nullptr && mySelectedNode->Parent != nullptr )
      {
         treeView1->SelectedNode = mySelectedNode;
         treeView1->LabelEdit = true;
         if (  !mySelectedNode->IsEditing )
         {
            mySelectedNode->BeginEdit();
         }
      }
      else
      {
         MessageBox::Show( String::Concat( "No tree node selected or selected node is a root node.\n",
            "Editing of root nodes is not allowed." ), "Invalid selection" );
      }
   }

   void treeView1_AfterLabelEdit( Object^ /*sender*/,
      System::Windows::Forms::NodeLabelEditEventArgs^ e )
   {
      if ( e->Label != nullptr )
      {
         if ( e->Label->Length > 0 )
         {
            array<Char>^ temp0 = {'@','.',',','!'};
            if ( e->Label->IndexOfAny( temp0 ) == -1 )
            {
               
               // Stop editing without canceling the label change.
               e->Node->EndEdit( false );
            }
            else
            {
               /* Cancel the label edit action, inform the user, and 
                  place the node in edit mode again. */
               e->CancelEdit = true;
               MessageBox::Show( String::Concat( "Invalid tree node label.\n",
                  "The invalid characters are: '@','.', ',', '!'" ),
                  "Node Label Edit" );
               e->Node->BeginEdit();
            }
         }
         else
         {
            /* Cancel the label edit action, inform the user, and 
               place the node in edit mode again. */
            e->CancelEdit = true;
            MessageBox::Show( "Invalid tree node label.\nThe label cannot be blank",
               "Node Label Edit" );
            e->Node->BeginEdit();
         }
      }
   }
/* Get the tree node under the mouse pointer and 
   save it in the mySelectedNode variable. */
private void treeView1_MouseDown(object sender, 
  System.Windows.Forms.MouseEventArgs e)
{
   mySelectedNode = treeView1.GetNodeAt(e.X, e.Y);
}

private void menuItem1_Click(object sender, System.EventArgs e)
{
   if (mySelectedNode != null && mySelectedNode.Parent != null)
   {
      treeView1.SelectedNode = mySelectedNode;
      treeView1.LabelEdit = true;
      if(!mySelectedNode.IsEditing)
      {
         mySelectedNode.BeginEdit();
      }
   }
   else
   {
      MessageBox.Show("No tree node selected or selected node is a root node.\n" + 
         "Editing of root nodes is not allowed.", "Invalid selection");
   }
}

private void treeView1_AfterLabelEdit(object sender, 
         System.Windows.Forms.NodeLabelEditEventArgs e)
{
   if (e.Label != null)
   {
     if(e.Label.Length > 0)
     {
        if (e.Label.IndexOfAny(new char[]{'@', '.', ',', '!'}) == -1)
        {
           // Stop editing without canceling the label change.
           e.Node.EndEdit(false);
        }
        else
        {
           /* Cancel the label edit action, inform the user, and 
              place the node in edit mode again. */
           e.CancelEdit = true;
           MessageBox.Show("Invalid tree node label.\n" + 
              "The invalid characters are: '@','.', ',', '!'", 
              "Node Label Edit");
           e.Node.BeginEdit();
        }
     }
     else
     {
        /* Cancel the label edit action, inform the user, and 
           place the node in edit mode again. */
        e.CancelEdit = true;
        MessageBox.Show("Invalid tree node label.\nThe label cannot be blank", 
           "Node Label Edit");
        e.Node.BeginEdit();
     }
   }
}
' Get the tree node under the mouse pointer and
' save it in the mySelectedNode variable. 
Private Sub treeView1_MouseDown(sender As Object, _
  e As System.Windows.Forms.MouseEventArgs)
        
   mySelectedNode = treeView1.GetNodeAt(e.X, e.Y)
End Sub    
    
Private Sub menuItem1_Click(sender As Object, e As System.EventArgs)
   If Not (mySelectedNode Is Nothing) And _
     Not (mySelectedNode.Parent Is Nothing) Then
      treeView1.SelectedNode = mySelectedNode
      treeView1.LabelEdit = True
      If Not mySelectedNode.IsEditing Then
         mySelectedNode.BeginEdit()
      End If
   Else
      MessageBox.Show("No tree node selected or selected node is a root node." & _
        Microsoft.VisualBasic.ControlChars.Cr & _
        "Editing of root nodes is not allowed.", "Invalid selection")
   End If
End Sub    
    
Private Sub treeView1_AfterLabelEdit(sender As Object, _
  e As System.Windows.Forms.NodeLabelEditEventArgs)
   If Not (e.Label Is Nothing) Then
      If e.Label.Length > 0 Then
         If e.Label.IndexOfAny(New Char() {"@"c, "."c, ","c, "!"c}) = -1 Then
            ' Stop editing without canceling the label change.
            e.Node.EndEdit(False)
         Else
            ' Cancel the label edit action, inform the user, and
            ' place the node in edit mode again. 
            e.CancelEdit = True
            MessageBox.Show("Invalid tree node label." & _
              Microsoft.VisualBasic.ControlChars.Cr & _
              "The invalid characters are: '@','.', ',', '!'", _
              "Node Label Edit")
            e.Node.BeginEdit()
         End If
      Else
         ' Cancel the label edit action, inform the user, and
         ' place the node in edit mode again. 
         e.CancelEdit = True
         MessageBox.Show("Invalid tree node label." & _
           Microsoft.VisualBasic.ControlChars.Cr & _
           "The label cannot be blank", "Node Label Edit")
           e.Node.BeginEdit()
      End If
   End If
End Sub 

설명

전달할 수 있습니다는 MouseEventArgs.XMouseEventArgs.Y 좌표를 MouseDown 이벤트로는 xy 매개 변수입니다.You can pass the MouseEventArgs.X and MouseEventArgs.Y coordinates of the MouseDown event as the x and y parameters.

추가 정보

적용 대상