TreeView.Indent 속성

정의

각 자식 트리 노드 수준을 들여 쓸 간격을 가져오거나 설정합니다.

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

속성 값

Int32

각 자식 트리 노드 수준을 들여 쓸 간격(픽셀 단위)입니다. 기본값은 19입니다.

예외

할당된 값이 0보다 작은 경우

또는

할당된 값이 32,000보다 큰 경우

예제

다음 코드 예제에서는 사용자 지정된 TreeView. 이 사용자 지정 버전은 클래스를 TreeView 상속하여 일반적인 TreeView모든 기능을 갖습니다. 생성자에서 다양 한 속성 값 변경에 고유한 모양을 제공 합니다. 속성이 ShowPlusMinus false로 설정되어 있으므로 사용자 지정된 컨트롤은 노드를 클릭할 때 확장 및 축소할 수 있도록 메서드를 재정 OnAfterSelect 의합니다.

이러한 방식으로 사용자 지정 된 컨트롤을 쉽게 컨트롤 속성을 개별 프로젝트 각각 지정 하지 않고도 일관 된 인터페이스를 제공 하는 조직 전반에 걸쳐 사용할 수 있습니다.

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

설명

값이 아직 기본값에서 변경되지 않은 경우 이 속성을 -1 값으로 설정해도 예외가 발생하지 않습니다. 컨트롤 핸들을 만들기 전에 컨트롤이 내부 기본값으로 -1 값을 사용하기 때문입니다. 이 내부 기본값은 래핑된 컨트롤이 자체 기본값인 19를 반환하도록 합니다.

적용 대상