TreeView.ShowPlusMinus TreeView.ShowPlusMinus TreeView.ShowPlusMinus TreeView.ShowPlusMinus Property

定义

获取或设置一个值,用以指示是否在包含子树节点的树节点旁显示加号 (+) 和减号 (-) 按钮。Gets or sets a value indicating whether plus-sign (+) and minus-sign (-) buttons are displayed next to tree nodes that contain child tree nodes.

public:
 property bool ShowPlusMinus { bool get(); void set(bool value); };
public bool ShowPlusMinus { get; set; }
member this.ShowPlusMinus : bool with get, set
Public Property ShowPlusMinus As Boolean

属性值

如果在包含子树节点的树节点旁显示加号和减号按钮,则为 true;否则为 falsetrue if plus sign and minus sign buttons are displayed next to tree nodes that contain child tree nodes; otherwise, false. 默认值为 trueThe default is true.

示例

下面的代码示例演示自定义TreeView的。The following code example illustrates a customized TreeView. 通过继承TreeView类, 此自定义版本具有典型TreeView的所有功能。By inheriting the TreeView class, this custom version has all the functionality of a typical 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 that 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 

注解

仅当ShowRootLines属性值为时true, 才会在根树节点旁显示加号和减号按钮。The plus sign and minus sign buttons appear next to the root tree nodes only if the ShowRootLines property value is true. 如果未显示加号和减号按钮, 则不存在视觉提示, 指示树节点包含子树节点且可展开。If the plus sign and minus sign buttons are not displayed, no visual cue exists to indicate that the tree node contains child tree nodes and is expandable. 然后, 用户必须双击树节点, 以确定它是否包含子树节点、展开它或折叠该节点。The user then must double-click a tree node to determine whether it contains child tree nodes, to expand it, or to collapse it.

适用于

另请参阅