TreeViewEventArgs TreeViewEventArgs TreeViewEventArgs TreeViewEventArgs Class

定义

AfterCheck 控件的以下事件提供数据:AfterCollapseAfterExpandAfterSelectTreeViewProvides 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

示例

下面的示例演示一个自定义TreeViewThe following example illustrates a customized TreeView. 通过继承TreeView类,此自定义版本具有一个普通的所有功能TreeViewBy 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()

获取当前实例的 TypeGets 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)

适用于

另请参阅