다음을 통해 공유


TreeNodeStates 열거형

정의

TreeNode가능한 상태를 나타내는 상수 정의

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class TreeNodeStates
[System.Flags]
public enum TreeNodeStates
[<System.Flags>]
type TreeNodeStates = 
Public Enum TreeNodeStates
상속
TreeNodeStates
특성

필드

Name Description
Selected 1

노드가 선택되어 있습니다.

Grayed 2

노드를 사용할 수 없습니다.

Checked 8

노드가 선택되어 있습니다.

Focused 16

노드에 포커스가 있습니다.

Default 32

노드가 기본 상태입니다.

Hot 64

노드가 핫입니다. 이 상태는 속성이 HotTracking 설정 true 되고 마우스 포인터가 노드 위에 있을 때 발생합니다.

Marked 128

노드가 표시됩니다.

Indeterminate 256

확정되지 않은 상태의 노드입니다.

ShowKeyboardCues 512

노드는 바로 가기 키를 나타내야 합니다.

예제

다음 예제에서는 소유자 그리기를 사용 하 여 컨트롤을 사용자 지정 하는 TreeView 방법을 보여 줍니다. 예제의 컨트롤은 TreeView 일반 노드 레이블과 함께 선택적 노드 태그를 표시합니다. 노드 태그는 속성을 사용하여 TreeNode.Tag 지정됩니다. 또한 컨트롤은 TreeView 사용자 지정 강조 색을 포함하여 사용자 지정 색을 사용합니다.

색 속성을 설정하여 대부분의 색을 TreeView 사용자 지정할 수 있지만 선택 강조 색은 속성으로 사용할 수 없습니다. 또한 기본 선택 강조 사각형은 노드 레이블 주위에만 확장됩니다. 소유자 드로잉은 노드 태그를 그리고 노드 태그를 포함할 수 있을 만큼 큰 사용자 지정된 강조 사각형을 그리는 데 사용해야 합니다.

이 예제에서 이벤트에 대한 TreeView.DrawNode 처리기는 클래스의 메서드를 호출하여 선택되지 않은 노드를 DrawTreeNodeEventArgs 그립니다. 이러한 메서드는 사용자 지정이 필요하지 않은 요소에 대한 TreeView 기본 모양을 제공합니다. 처리기는 노드 태그를 그리고 사용자 지정 선택 강조 표시를 수동으로 그립니다.

전체 예제는 참조 항목을 참조하세요 TreeView.DrawNode .

   // Draws a node.
private:
   void myTreeView_DrawNode( Object^ sender, DrawTreeNodeEventArgs^ e )
   {
      // Draw the background and node text for a selected node.
      if ( (e->State & TreeNodeStates::Selected) != (TreeNodeStates)0 )
      {
         // Draw the background of the selected node. The NodeBounds
         // method makes the highlight rectangle large enough to
         // include the text of a node tag, if one is present.
         e->Graphics->FillRectangle( Brushes::Green, NodeBounds( e->Node ) );

         // Retrieve the node font. If the node font has not been set,
         // use the TreeView font.
         System::Drawing::Font^ nodeFont = e->Node->NodeFont;
         if ( nodeFont == nullptr )
                  nodeFont = (dynamic_cast<TreeView^>(sender))->Font;

         // Draw the node text.
         e->Graphics->DrawString( e->Node->Text, nodeFont, Brushes::White, Rectangle::Inflate( e->Bounds, 2, 0 ) );
      }
      // Use the default background and node text.
      else
      {
         e->DrawDefault = true;
      }

      // If a node tag is present, draw its string representation 
      // to the right of the label text.
      if ( e->Node->Tag != nullptr )
      {
         e->Graphics->DrawString( e->Node->Tag->ToString(), tagFont, Brushes::Yellow, (float)e->Bounds.Right + 2, (float)e->Bounds.Top );
      }

      
      // If the node has focus, draw the focus rectangle large, making
      // it large enough to include the text of the node tag, if present.
      if ( (e->State & TreeNodeStates::Focused) != (TreeNodeStates)0 )
      {
         Pen^ focusPen = gcnew Pen( Color::Black );
         try
         {
            focusPen->DashStyle = System::Drawing::Drawing2D::DashStyle::Dot;
            Rectangle focusBounds = NodeBounds( e->Node );
            focusBounds.Size = System::Drawing::Size( focusBounds.Width - 1, focusBounds.Height - 1 );
            e->Graphics->DrawRectangle( focusPen, focusBounds );
         }
         finally
         {
            if ( focusPen )
               delete safe_cast<IDisposable^>(focusPen);
         }

      }
   }
// Draws a node.
private void myTreeView_DrawNode(
    object sender, DrawTreeNodeEventArgs e)
{
    // Draw the background and node text for a selected node.
    if ((e.State & TreeNodeStates.Selected) != 0)
    {
        // Draw the background of the selected node. The NodeBounds
        // method makes the highlight rectangle large enough to
        // include the text of a node tag, if one is present.
        e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node));

        // Retrieve the node font. If the node font has not been set,
        // use the TreeView font.
        Font nodeFont = e.Node.NodeFont;
        if (nodeFont == null) nodeFont = ((TreeView)sender).Font;

        // Draw the node text.
        e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White,
            Rectangle.Inflate(e.Bounds, 2, 0));
    }

    // Use the default background and node text.
    else 
    {
        e.DrawDefault = true;
    }

    // If a node tag is present, draw its string representation 
    // to the right of the label text.
    if (e.Node.Tag != null)
    {
        e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont,
            Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top);
    }

    // If the node has focus, draw the focus rectangle large, making
    // it large enough to include the text of the node tag, if present.
    if ((e.State & TreeNodeStates.Focused) != 0)
    {
        using (Pen focusPen = new Pen(Color.Black))
        {
            focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
            Rectangle focusBounds = NodeBounds(e.Node);
            focusBounds.Size = new Size(focusBounds.Width - 1, 
            focusBounds.Height - 1);
            e.Graphics.DrawRectangle(focusPen, focusBounds);
        }
    }
}
' Draws a node.
Private Sub myTreeView_DrawNode(ByVal sender As Object, _
    ByVal e As DrawTreeNodeEventArgs) Handles myTreeView.DrawNode

    ' Draw the background and node text for a selected node.
    If (e.State And TreeNodeStates.Selected) <> 0 Then

        ' Draw the background of the selected node. The NodeBounds
        ' method makes the highlight rectangle large enough to
        ' include the text of a node tag, if one is present.
        e.Graphics.FillRectangle(Brushes.Green, NodeBounds(e.Node))

        ' Retrieve the node font. If the node font has not been set,
        ' use the TreeView font.
        Dim nodeFont As Font = e.Node.NodeFont
        If nodeFont Is Nothing Then
            nodeFont = CType(sender, TreeView).Font
        End If

        ' Draw the node text.
        e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, _
            e.Bounds.Left - 2, e.Bounds.Top)

    ' Use the default background and node text.
    Else
        e.DrawDefault = True
    End If

    ' If a node tag is present, draw its string representation 
    ' to the right of the label text.
    If (e.Node.Tag IsNot Nothing) Then
        e.Graphics.DrawString(e.Node.Tag.ToString(), tagFont, _
            Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top)
    End If

    ' If the node has focus, draw the focus rectangle large, making
    ' it large enough to include the text of the node tag, if present.
    If (e.State And TreeNodeStates.Focused) <> 0 Then
        Dim focusPen As New Pen(Color.Black)
        Try
            focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot
            Dim focusBounds As Rectangle = NodeBounds(e.Node)
            focusBounds.Size = New Size(focusBounds.Width - 1, _
                focusBounds.Height - 1)
            e.Graphics.DrawRectangle(focusPen, focusBounds)
        Finally
            focusPen.Dispose()
        End Try
    End If

End Sub

설명

이 열거형은 클래스의 속성에 StateDrawTreeNodeEventArgs 사용됩니다. 자세한 내용은 이벤트를 참조하세요 TreeView.DrawNode .

적용 대상

추가 정보