Nyelv

TreeView.Indent Tulajdonság

Definíció

Lekéri vagy beállítja az egyes gyermekfa csomópontszintek behúzásának távolságát.

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

Tulajdonság értéke

A gyermekfa csomópontszintjeinek behúzásához megadott távolság képpontban. Az alapértelmezett érték 19.

Kivételek

A hozzárendelt érték kisebb, mint 0.

-vagy-

A hozzárendelt érték nagyobb, mint 32 000.

Példák

Az alábbi példakód egy testre szabott TreeViewkódot mutat be. Az osztály öröklésével ez az TreeView egyéni verzió egy tipikus TreeViewfunkcióval rendelkezik. A konstruktor különböző tulajdonságértékeinek módosítása egyedi megjelenést biztosít. Mivel a ShowPlusMinus tulajdonság értéke hamis, a testreszabott vezérlő felülbírálja a metódust is, így a OnAfterSelect csomópontok kibonthatók és összecsukhatók, amikor rákattintanak.

Az ilyen módon testre szabott vezérlők a szervezet egészében használhatók, így egyszerűen konzisztens felületet biztosíthat anélkül, hogy minden egyes projektben meg kellene adni a vezérlőtulajdonságokat.

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

Megjegyzések

Ha ezt a tulajdonságot -1 értékre állítja, az nem okoz kivételt, ha az érték még nem változott az alapértelmezett értékről. Ennek az az oka, hogy a vezérlő -1 értéket használ belső alapértelmezettként a vezérlőfogópont létrehozása előtt. Ez a belső alapértelmezett érték miatt a burkolt vezérlőelem a saját alapértelmezett értékét adja vissza 19-nek.

A következőre érvényes: