Поделиться через


TreeViewEventArgs Класс

Определение

Предоставляет данные для AfterCheckэлемента управления , AfterExpandAfterCollapseили AfterSelect событий TreeView элемента управления.

public ref class TreeViewEventArgs : EventArgs
public class TreeViewEventArgs : EventArgs
type TreeViewEventArgs = class
    inherit EventArgs
Public Class TreeViewEventArgs
Inherits EventArgs
Наследование
TreeViewEventArgs

Примеры

В следующем примере показан настраиваемый TreeViewобъект. Наследуя TreeView класс, эта пользовательская версия имеет все функциональные возможности нормального TreeView. Изменение различных значений свойств в конструкторе обеспечивает уникальный внешний вид. ShowPlusMinus Так как свойство имеет значение false, настраиваемый элемент управления также переопределяет OnAfterSelect метод, чтобы узлы могли быть развернуты и свернуты при щелчке.

Элемент управления, настроенный таким образом, можно использовать во всей организации, что упрощает предоставление согласованного интерфейса без необходимости указывать свойства элемента управления в каждом отдельном проекте.

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

Комментарии

Дополнительные сведения об обработке событий см. в разделе "Обработка и создание событий".

Конструкторы

Имя Описание
TreeViewEventArgs(TreeNode, TreeViewAction)

Инициализирует новый экземпляр TreeViewEventArgs класса для указанного узла дерева и с указанным типом действия, вызвавшее событие.

TreeViewEventArgs(TreeNode)

Инициализирует новый экземпляр класса для указанного TreeViewEventArgs узла дерева.

Свойства

Имя Описание
Action

Возвращает тип действия, вызвавшее событие.

Node

Возвращает узел дерева, который был проверен, развернут, свернут или выбран.

Методы

Имя Описание
Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает Type текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неглубокую копию текущей Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Применяется к

См. также раздел