TreeView.ShowPlusMinus Propriedade

Definição

Obtém ou define um valor que indica se os botões do sinal de adição (+) e do sinal de subtração (-) são exibidos ao lado de nós de árvore que contêm nós de árvores filhos.

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 da propriedade

Boolean

true se os botões do sinal de adição e do sinal de subtração são exibidos ao lado de nós de árvore que contêm nós de árvores filhos; caso contrário, false. O padrão é true.

Exemplos

O exemplo de código a seguir ilustra um .TreeView Ao herdar a TreeView classe, essa versão personalizada tem toda a funcionalidade de um típico TreeView. Alterar vários valores de propriedade no construtor fornece uma aparência exclusiva. Como a ShowPlusMinus propriedade é definida como false, o controle personalizado também substitui o método para que os OnAfterSelect nós possam ser expandidos e recolhidos quando são clicados.

Um controle personalizado dessa forma pode ser usado em toda uma organização, facilitando o uso de uma interface consistente sem exigir que as propriedades de controle sejam especificadas em cada projeto 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

Comentários

Os botões sinal de adição e sinal de menos aparecem ao lado dos nós de árvore raiz somente se o valor da ShowRootLines propriedade for true. Se os botões sinal de adição e sinal de subtração não forem exibidos, nenhuma indicação visual existirá para indicar que o nó de árvore contém nós de árvore filho e é expansível. Em seguida, o usuário deve clicar duas vezes em um nó de árvore para determinar se ele contém nós de árvore filho, para expandi-lo ou para recolhê-lo.

Aplica-se a

Confira também