TreeViewEventArgs TreeViewEventArgs TreeViewEventArgs TreeViewEventArgs Class

Определение

Предоставляет данные для событий AfterCheck, AfterCollapse, AfterExpand или AfterSelect элемента управления TreeView.Provides data for the AfterCheck, AfterCollapse, AfterExpand, or AfterSelect events of a TreeView control.

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

Примеры

В следующем примере показан настраиваемый TreeView.The following example illustrates a customized TreeView. Путем наследования TreeView класс, этой пользовательской версии имеет все функции обычной TreeView.By inheriting the TreeView class, this custom version has all the functionality of a normal TreeView. Изменение значений различных свойств в конструкторе предоставляет уникальный внешний вид.Changing various property values in the constructor provides a unique appearance. Так как ShowPlusMinus свойство имеет значение false, настраиваемый элемент управления также переопределяет OnAfterSelect метод узлов можно разворачивать и сворачивать при щелчке.Because the ShowPlusMinus property is set to false, the customized control also overrides the OnAfterSelect method so nodes can be expanded and collapsed when they are clicked.

Элемент управления, который настроен таким образом может использоваться во всей организации, что упрощает для обеспечения согласованного интерфейса без необходимости свойства элементов управления в каждом проекте отдельно.A control that is customized in this way can be used throughout an organization, making it easy to provide a consistent interface without requiring the control properties to be specified in each individual project.

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 'New


    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 'OnAfterSelect

End Class 'CustomizedTreeView 

Комментарии

Дополнительные сведения об обработке событий см. в разделе обработка и вызов событий.For more information about handling events, see Handling and Raising Events.

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

TreeViewEventArgs(TreeNode) TreeViewEventArgs(TreeNode) TreeViewEventArgs(TreeNode) TreeViewEventArgs(TreeNode)

Инициализирует новый экземпляр класса TreeViewEventArgs для указанного узла дерева.Initializes a new instance of the TreeViewEventArgs class for the specified tree node.

TreeViewEventArgs(TreeNode, TreeViewAction) TreeViewEventArgs(TreeNode, TreeViewAction) TreeViewEventArgs(TreeNode, TreeViewAction) TreeViewEventArgs(TreeNode, TreeViewAction)

Инициализирует новый экземпляр класса TreeViewEventArgs для указанного узла дерева с заданным типом действия, которое вызвало событие.Initializes a new instance of the TreeViewEventArgs class for the specified tree node and with the specified type of action that raised the event.

Свойства

Action Action Action Action

Возвращает тип действия, которое вызвало событие.Gets the type of action that raised the event.

Node Node Node Node

Возвращает узел дерева, который выделен, развернут, свернут или выбран.Gets the tree node that has been checked, expanded, collapsed, or selected.

Методы

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

Определяет, равен ли заданный объект текущему объекту.Determines whether the specified object is equal to the current object.

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

Служит хэш-функцией по умолчанию.Serves as the default hash function.

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

Возвращает объект Type для текущего экземпляра.Gets the Type of the current instance.

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

Создает неполную копию текущего объекта Object.Creates a shallow copy of the current Object.

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

Возвращает строку, представляющую текущий объект.Returns a string that represents the current object.

(Inherited from Object)

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

Дополнительно