TreeNodeStates 열거형

정의

TreeNode의 가능한 상태를 나타내는 상수를 정의합니다.

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

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

필드

Checked 8

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

Default 32

노드가 기본 상태에 있습니다.

Focused 16

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

Grayed 2

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

Hot 64

노드에 핫 트래킹을 사용합니다. HotTracking 속성이 true로 설정되어 있을 때 마우스 포인터를 노드 위에 가져가면 이 상태가 됩니다.

Indeterminate 256

노드가 결정되지 않은 상태에 있습니다.

Marked 128

노드가 표시되어 있습니다.

Selected 1

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

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

설명

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

적용 대상

추가 정보