Freigeben über


TreeView.Indent Eigenschaft

Definition

Dient zum Abrufen oder Festlegen des Abstands zum Einzug der einzelnen untergeordneten Strukturknotenebenen.

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

Eigenschaftswert

Der Abstand in Pixel, um die einzelnen untergeordneten Strukturknotenebenen einzurücken. Der Standardwert ist 19.

Ausnahmen

Der zugewiesene Wert ist kleiner als 0.

- oder -

Der zugewiesene Wert ist größer als 32.000.

Beispiele

Das folgende Codebeispiel veranschaulicht eine angepasste TreeView. Durch das Erben der TreeView Klasse verfügt diese benutzerdefinierte Version über alle Funktionen einer typischen TreeView. Das Ändern verschiedener Eigenschaftswerte im Konstruktor bietet eine eindeutige Darstellung. Da die ShowPlusMinus Eigenschaft auf "false" festgelegt ist, überschreibt das angepasste Steuerelement auch die OnAfterSelect Methode, sodass Knoten erweitert und reduziert werden können, wenn auf sie geklickt werden.

Ein Steuerelement, das auf diese Weise angepasst wird, kann in der gesamten Organisation verwendet werden, sodass es einfach ist, eine konsistente Schnittstelle bereitzustellen, ohne dass die Steuerelementeigenschaften in jedem einzelnen Projekt angegeben werden müssen.

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

Hinweise

Wenn Sie diese Eigenschaft auf einen Wert von -1 festlegen, wird keine Ausnahme ausgelöst, wenn der Wert noch nicht von der Standardeinstellung geändert wurde. Dies liegt daran, dass das Steuerelement einen Wert von -1 als internen Standard verwendet, bevor der Steuerpunkt erstellt wurde. Dieser interne Standardwert bewirkt, dass das umschlossene Steuerelement seinen eigenen Standardwert von 19 zurückgibt.

Gilt für: