Sdílet prostřednictvím


TreeViewEventArgs Třída

Definice

Poskytuje data pro ovládací prvek AfterCheck, AfterCollapse, AfterExpandnebo AfterSelect události TreeView ovládacího prvku.

public ref class TreeViewEventArgs : EventArgs
public class TreeViewEventArgs : EventArgs
type TreeViewEventArgs = class
    inherit EventArgs
Public Class TreeViewEventArgs
Inherits EventArgs
Dědičnost
TreeViewEventArgs

Příklady

Následující příklad znázorňuje přizpůsobenou TreeView. Děděním TreeView třídy má tato vlastní verze všechny funkce normálního TreeView. Změna různých hodnot vlastností v konstruktoru poskytuje jedinečný vzhled. Vzhledem k tomu, že ShowPlusMinus vlastnost je nastavena na false, vlastní ovládací prvek také přepíše metodu OnAfterSelect , takže uzly lze rozbalit a sbalit při kliknutí.

Ovládací prvek, který je tímto způsobem přizpůsobený, lze použít v celé organizaci, což usnadňuje poskytování konzistentního rozhraní bez nutnosti zadat vlastnosti ovládacího prvku v každém jednotlivém projektu.

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

Poznámky

Další informace o zpracování událostí naleznete v tématu Zpracování a vyvolávání událostí.

Konstruktory

Name Description
TreeViewEventArgs(TreeNode, TreeViewAction)

Inicializuje novou instanci TreeViewEventArgs třídy pro zadaný uzel stromu a se zadaným typem akce, která vyvolala událost.

TreeViewEventArgs(TreeNode)

Inicializuje novou instanci TreeViewEventArgs třídy pro zadaný uzel stromu.

Vlastnosti

Name Description
Action

Získá typ akce, která vyvolala událost.

Node

Získá uzel stromu, který je zaškrtnutý, rozbalený, sbalený nebo vybraný.

Metody

Name Description
Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Viz také