Condividi tramite


TreeView.Indent Proprietà

Definizione

Ottiene o imposta la distanza in base al rientro di ogni livello del nodo dell'albero figlio.

public:
 property int Indent { int get(); void set(int value); };
public int Indent { get; set; }
member this.Indent : int with get, set
Public Property Indent As Integer

Valore della proprietà

Distanza, in pixel, per rientrare ogni livello del nodo dell'albero figlio. Il valore predefinito è 19.

Eccezioni

Il valore assegnato è minore di 0.

oppure

Il valore assegnato è maggiore di 32.000.

Esempio

Nell'esempio di codice seguente viene illustrato un oggetto TreeViewpersonalizzato. Ereditando la TreeView classe , questa versione personalizzata ha tutte le funzionalità di un tipico TreeViewoggetto . La modifica di vari valori di proprietà nel costruttore offre un aspetto univoco. Poiché la ShowPlusMinus proprietà è impostata su false, il controllo personalizzato esegue anche l'override del OnAfterSelect metodo in modo che i nodi possano essere espansi e compressi quando vengono selezionati.

Un controllo personalizzato in questo modo può essere usato in tutta un'organizzazione, semplificando la creazione di un'interfaccia coerente senza che le proprietà del controllo vengano specificate in ogni singolo progetto.

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

Commenti

L'impostazione di questa proprietà su un valore di -1 non genera un'eccezione se il valore non è ancora stato modificato rispetto al valore predefinito. Questo perché il controllo utilizza un valore di -1 come valore predefinito interno prima che l'handle di controllo sia stato creato. Questo valore predefinito interno fa sì che il controllo di cui è stato eseguito il wrapping restituisca il valore predefinito 19.

Si applica a