Condividi tramite


TreeViewEventArgs Classe

Definizione

Fornisce dati per gli AfterCheckeventi , AfterExpandAfterCollapse, o AfterSelect di un TreeView controllo .

public ref class TreeViewEventArgs : EventArgs
public class TreeViewEventArgs : EventArgs
type TreeViewEventArgs = class
    inherit EventArgs
Public Class TreeViewEventArgs
Inherits EventArgs
Ereditarietà
TreeViewEventArgs

Esempio

Nell'esempio seguente viene illustrato un oggetto personalizzato TreeView. Ereditando la TreeView classe , questa versione personalizzata ha tutte le funzionalità di un normale TreeView. La modifica di vari valori di proprietà nel costruttore offre un aspetto univoco. Poiché la ShowPlusMinus proprietà è impostata su false, il controllo personalizzato esegue anche l'override del OnAfterSelect metodo in modo che i nodi possano essere espansi e compressi quando vengono selezionati.

Un controllo personalizzato in questo modo può essere usato in tutta un'organizzazione, semplificando la creazione di un'interfaccia coerente senza che le proprietà del controllo vengano specificate in ogni singolo progetto.

public ref class CustomizedTreeView: public TreeView
{
public:
   CustomizedTreeView()
   {

      // Customize the TreeView control by setting various properties.
      BackColor = System::Drawing::Color::CadetBlue;
      FullRowSelect = true;
      HotTracking = true;
      Indent = 34;
      ShowPlusMinus = false;

      // The ShowLines property must be false for the FullRowSelect
      // property to work.
      ShowLines = false;
   }

protected:
   virtual void OnAfterSelect( TreeViewEventArgs^ e ) override
   {
      // Confirm that the user initiated the selection.
      // This prevents the first node from expanding when it is
      // automatically selected during the initialization of
      // the TreeView control.
      if ( e->Action != TreeViewAction::Unknown )
      {
         if ( e->Node->IsExpanded )
         {
            e->Node->Collapse();
         }
         else
         {
            e->Node->Expand();
         }
      }

      
      // Remove the selection. This allows the same node to be
      // clicked twice in succession to toggle the expansion state.
      SelectedNode = nullptr;
   }
};
public class CustomizedTreeView : TreeView
{
    public CustomizedTreeView()
    {
        // Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue;
        FullRowSelect = true;
        HotTracking = true;
        Indent = 34;
        ShowPlusMinus = false;

        // The ShowLines property must be false for the FullRowSelect 
        // property to work.
        ShowLines = false;
    }

    protected override void OnAfterSelect(TreeViewEventArgs e)
    {
        // Confirm that the user initiated the selection.
        // This prevents the first node from expanding when it is
        // automatically selected during the initialization of 
        // the TreeView control.
        if (e.Action != TreeViewAction.Unknown)
        {
            if (e.Node.IsExpanded) 
            {
                e.Node.Collapse();
            }
            else 
            {
                e.Node.Expand();
            }
        }

        // Remove the selection. This allows the same node to be
        // clicked twice in succession to toggle the expansion state.
        SelectedNode = null;
    }
}
Public Class CustomizedTreeView
    Inherits TreeView

    Public Sub New()
        ' Customize the TreeView control by setting various properties.
        BackColor = System.Drawing.Color.CadetBlue
        FullRowSelect = True
        HotTracking = True
        Indent = 34
        ShowPlusMinus = False

        ' The ShowLines property must be false for the FullRowSelect 
        ' property to work.
        ShowLines = False
    End Sub


    Protected Overrides Sub OnAfterSelect(ByVal e As TreeViewEventArgs)
        ' Confirm that the user initiated the selection.
        ' This prevents the first node from expanding when it is
        ' automatically selected during the initialization of 
        ' the TreeView control.
        If e.Action <> TreeViewAction.Unknown Then
            If e.Node.IsExpanded Then
                e.Node.Collapse()
            Else
                e.Node.Expand()
            End If
        End If

        ' Remove the selection. This allows the same node to be
        ' clicked twice in succession to toggle the expansion state.
        SelectedNode = Nothing
    End Sub

End Class

Commenti

Per ulteriori informazioni sulla gestione degli eventi, consultare gestione e generazione di eventi.

Costruttori

Nome Descrizione
TreeViewEventArgs(TreeNode, TreeViewAction)

Inizializza una nuova istanza della TreeViewEventArgs classe per il nodo della struttura ad albero specificato e con il tipo di azione specificato che ha generato l'evento.

TreeViewEventArgs(TreeNode)

Inizializza una nuova istanza della TreeViewEventArgs classe per il nodo della struttura ad albero specificato.

Proprietà

Nome Descrizione
Action

Ottiene il tipo di azione che ha generato l'evento.

Node

Ottiene il nodo della struttura ad albero selezionato, espanso, compresso o selezionato.

Metodi

Nome Descrizione
Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a

Vedi anche