TreeView.Indent Vlastnost

Definice

Získá nebo nastaví vzdálenost odsazení každé podřízené stromové úrovně uzlu.

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

Hodnota vlastnosti

Vzdálenost (v pixelech) pro odsazení jednotlivých úrovní uzlů podřízeného stromu Výchozí hodnota je 19.

Výjimky

Přiřazená hodnota je menší než 0.

-nebo-

Přiřazená hodnota je větší než 32 000.

Příklady

Následující příklad kódu znázorňuje přizpůsobený TreeViewkód . Díky dědění TreeView třídy má tato vlastní verze všechny funkce typické TreeViewtřídy . Změna různých hodnot vlastností v konstruktoru poskytuje jedinečný vzhled. ShowPlusMinus Vzhledem k tomu, že vlastnost je nastavena na false, přizpůsobený ovládací prvek také přepíše metodu OnAfterSelect tak, aby uzly bylo možné rozbalit a sbalit při kliknutí.

Ovládací prvek, který je přizpůsobený tímto způsobem, lze použít v celé organizaci, což usnadňuje poskytování konzistentního rozhraní bez nutnosti zadávat vlastnosti ovládacího prvku v každém jednotlivém projektu.

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

Poznámky

Nastavení této vlastnosti na hodnotu -1 nevyvolá výjimku, pokud hodnota ještě nebyla změněna z výchozí hodnoty. Je to proto, že ovládací prvek používá hodnotu -1 jako interní výchozí hodnotu před vytvořením popisovače ovládacího prvku. Tato interní výchozí hodnota způsobí, že zabalený ovládací prvek vrátí vlastní výchozí hodnotu 19.

Platí pro