Partager via


TreeView.Indent Propriété

Définition

Obtient ou définit la distance à mettre en retrait chaque niveau de nœud d’arbre enfant.

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

Valeur de propriété

Distance, en pixels, pour mettre en retrait chaque niveau de nœud d’arbre enfant. La valeur par défaut est 19.

Exceptions

La valeur affectée est inférieure à 0.

- ou -

La valeur affectée est supérieure à 32 000.

Exemples

L’exemple de code suivant illustre un code personnalisé TreeView. En héritant de la TreeView classe, cette version personnalisée a toutes les fonctionnalités d’une version classique TreeView. La modification de différentes valeurs de propriété dans le constructeur offre une apparence unique. Étant donné que la ShowPlusMinus propriété est définie sur false, le contrôle personnalisé remplace également la OnAfterSelect méthode afin que les nœuds puissent être développés et réduits lorsqu’ils sont cliqués.

Un contrôle personnalisé de cette façon peut être utilisé au sein d’une organisation, ce qui facilite la fourniture d’une interface cohérente sans que les propriétés de contrôle soient spécifiées dans chaque projet individuel.

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

Remarques

La définition de cette propriété sur une valeur de -1 ne lève pas d’exception si la valeur n’a pas encore été modifiée par défaut. Cela est dû au fait que le contrôle utilise une valeur de -1 comme valeur par défaut interne avant la création du handle de contrôle. Cette valeur par défaut interne entraîne le retour du contrôle encapsulé de sa propre valeur par défaut de 19.

S’applique à