TreeView.ShowPlusMinus Propiedad

Definición

Obtiene o establece un valor que indica si se muestran botones con los signos más (+) y menos (-) al lado de los nodos de árbol que contienen nodos de árbol secundarios.

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

Valor de propiedad

Boolean

Es true si se muestran botones con los signos más (+) y menos (-) junto a los nodos de árbol que contienen nodos de árbol secundarios; en caso contrario, es false. De manera predeterminada, es true.

Ejemplos

En el ejemplo de código siguiente se muestra un personalizado TreeView. Al heredar la TreeView clase , esta versión personalizada tiene toda la funcionalidad de un típico TreeView. El cambio de varios valores de propiedad en el constructor proporciona una apariencia única. Dado que la ShowPlusMinus propiedad se establece en false, el control personalizado también invalida el OnAfterSelect método para que los nodos se puedan expandir y contraer cuando se hace clic en ellos.

Un control que se personaliza de esta manera se puede usar en toda una organización, lo que facilita proporcionar una interfaz coherente sin necesidad de especificar las propiedades de control en cada proyecto individual.

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

Comentarios

Los botones signo más y signo menos aparecen junto a los nodos del árbol raíz solo si el valor de la ShowRootLines propiedad es true. Si no se muestran los botones signo más y signo menos, no existe ninguna indicación visual para indicar que el nodo de árbol contiene nodos de árbol secundarios y se puede expandir. A continuación, el usuario debe hacer doble clic en un nodo de árbol para determinar si contiene nodos de árbol secundarios, expandirlo o contraerlo.

Se aplica a

Consulte también