NodeLabelEditEventArgs NodeLabelEditEventArgs NodeLabelEditEventArgs NodeLabelEditEventArgs Class

Definición

Proporciona datos para los eventos BeforeLabelEdit y AfterLabelEdit.Provides data for the BeforeLabelEdit and AfterLabelEdit events.

public ref class NodeLabelEditEventArgs : EventArgs
public class NodeLabelEditEventArgs : EventArgs
type NodeLabelEditEventArgs = class
    inherit EventArgs
Public Class NodeLabelEditEventArgs
Inherits EventArgs
Herencia
NodeLabelEditEventArgsNodeLabelEditEventArgsNodeLabelEditEventArgsNodeLabelEditEventArgs

Ejemplos

En el siguiente ejemplo permite al usuario modificar los nodos de nodos de árbol mediante el uso de un ContextMenu.The following example allows the user to edit nonroot tree nodes by using a ContextMenu. Cuando el usuario hace clic con el mouse, el TreeNode de dicha posición determina y almacenan en una variable denominada mySelectedNode.When the user right clicks the mouse, the TreeNode at that position is determined and stored in a variable named mySelectedNode. Si se ha seleccionado un nodo de árbol sin raíz, se pone en 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, allowing the user to edit the node label. Después de que el usuario termina de editar la etiqueta del nodo de árbol, se evalúa y se guarda el nuevo texto de etiqueta.After the user stops editing the tree node label, the new label text is evaluated and saved. En este ejemplo, varios caracteres se consideran no válidos en el texto de 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 la etiqueta o la cadena está vacía, se notifica al usuario del error y la etiqueta se devuelve el 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

El AfterLabelEdit evento tiene lugar cuando el usuario termina de editar el texto de un nodo de árbol.The AfterLabelEdit event occurs when the user finishes editing the text for a tree node. El BeforeLabelEdit evento tiene lugar cuando el usuario comienza a editar el texto de un nodo de árbol.The BeforeLabelEdit event occurs when the user begins editing the text for a tree node. Un NodeLabelEditEventArgs objeto especifica el nuevo texto para asociar el nodo de árbol, el nodo de árbol que contiene la etiqueta editar, y si se ha cancelado la operación de edición.A NodeLabelEditEventArgs object specifies the new text to associate with the tree node, the tree node that contains the label to edit, and whether the edit operation has been canceled.

Para obtener más información sobre el manejo de eventos, consulte controlar y provocar eventos.For more information about handling events, see Handling and Raising Events.

Constructores

NodeLabelEditEventArgs(TreeNode) NodeLabelEditEventArgs(TreeNode) NodeLabelEditEventArgs(TreeNode) NodeLabelEditEventArgs(TreeNode)

Inicializa una nueva instancia de la clase NodeLabelEditEventArgs para el objetoTreeNode especificado.Initializes a new instance of the NodeLabelEditEventArgs class for the specified TreeNode.

NodeLabelEditEventArgs(TreeNode, String) NodeLabelEditEventArgs(TreeNode, String) NodeLabelEditEventArgs(TreeNode, String) NodeLabelEditEventArgs(TreeNode, String)

Inicializa una nueva instancia de la clase NodeLabelEditEventArgs para el TreeNode especificado y el texto especificado con el que actualizar la etiqueta de nodo de árbol.Initializes a new instance of the NodeLabelEditEventArgs class for the specified TreeNode and the specified text with which to update the tree node label.

Propiedades

CancelEdit CancelEdit CancelEdit CancelEdit

Obtiene o establece un valor que indica si se ha cancelado la edición.Gets or sets a value indicating whether the edit has been canceled.

Label Label Label Label

Obtiene el nuevo texto que se va a asociar al nodo de árbol.Gets the new text to associate with the tree node.

Node Node Node Node

Obtiene el nodo de árbol que contiene el texto que se va a editar.Gets the tree node containing the text to edit.

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Se aplica a

Consulte también: