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

Definición

Recupera el nodo de árbol situado en la ubicación especificada.Retrieves the tree node that is at the specified location.

Sobrecargas

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

Recupera el nodo de árbol situado en el punto especificado.Retrieves the tree node that is at the specified point.

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

Recupera el nodo de árbol situado en el punto con las coordenadas especificadas.Retrieves the tree node at the point with the specified coordinates.

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

Recupera el nodo de árbol situado en el punto especificado.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

Parámetros

pt
Point Point Point Point

Point que se utiliza para evaluar y recuperar el nodo.The Point to evaluate and retrieve the node from.

Devoluciones

El TreeNode en el punto especificado, en coordenadas de la vista de árbol (cliente), o null si no hay ningún nodo en esa ubicación.The TreeNode at the specified point, in tree view (client) coordinates, or null if there is no node at that location.

Comentarios

MouseEventArgs.X Puede pasar las coordenadas y MouseEventArgs.Y del Y X MouseDown evento como los valores y de un nuevo 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.

Consulte también:

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

Recupera el nodo de árbol situado en el punto con las coordenadas especificadas.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

Parámetros

x
Int32 Int32 Int32 Int32

Posición de X que se utiliza para evaluar y recuperar el nodo.The X position to evaluate and retrieve the node from.

y
Int32 Int32 Int32 Int32

Posición de Y que se utiliza para evaluar y recuperar el nodo.The Y position to evaluate and retrieve the node from.

Devoluciones

TreeNode en la ubicación especificada, en coordenadas de la vista de árbol (cliente), o null si no hay ningún nodo en esa ubicación.The TreeNode at the specified location, in tree view (client) coordinates, or null if there is no node at that location.

Ejemplos

En el ejemplo de código siguiente se permite al usuario editar nodos de árbol no ContextMenuraíz mediante.The following code example lets the user edit nonroot tree nodes by using a ContextMenu. Cuando el usuario hace clic con el botón secundario del TreeNode mouse, se determina el en esa posición y se almacena mySelectedNodeen una variable denominada.When the user right clicks the mouse, the TreeNode at that position is determined and stored in a variable named mySelectedNode. Si se seleccionó un nodo de árbol no raíz, se coloca en un estado editable, lo que permite al usuario editar la etiqueta del nodo.If a nonroot tree node was selected, it is put into an editable state, which allows the user to edit the node label. Después de que el usuario deje de editar la etiqueta del nodo de árbol, se evaluará y guardará el texto de la nueva etiqueta.After the user stops editing the tree node label, the new label text is evaluated and saved. En este ejemplo, se considera que varios caracteres no son válidos en el texto de la etiqueta.For this example, several characters are considered not valid in the label text. Si uno de los caracteres no válidos se encuentra en la cadena de etiqueta, o la cadena está vacía, se notifica al usuario del error y la etiqueta se devuelve a su texto anterior.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 

Comentarios

MouseEventArgs.X Puede pasar las coordenadas y MouseEventArgs.Y del MouseDown evento como los x parámetros y y .You can pass the MouseEventArgs.X and MouseEventArgs.Y coordinates of the MouseDown event as the x and y parameters.

Consulte también:

Se aplica a