DrawTreeNodeEventArgs.State 속성

정의

그릴 TreeNode의 현재 상태를 가져옵니다.

public:
 property System::Windows::Forms::TreeNodeStates State { System::Windows::Forms::TreeNodeStates get(); };
public System.Windows.Forms.TreeNodeStates State { get; }
member this.State : System.Windows.Forms.TreeNodeStates
Public ReadOnly Property State As TreeNodeStates

속성 값

TreeNodeStates의 현재 상태를 나타내는 TreeNode 값의 비트 조합입니다.

예제

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

대부분의 사용자 지정할 수 있습니다는 TreeView 색 속성을 설정 하 여 색 있지만 선택 강조 색 속성으로 사용할 수 없습니다. 또한 노드 레이블 주위에 기본 선택 항목 강조 표시 사각형을 확장합니다. 소유자 그리기는 노드 태그를 그릴 및 노드 태그를 포함 하도록 충분히 큰 사용자 지정된 강조 표시 사각형을 그리려면 사용 되어야 합니다.

예에 대 한 처리기를 TreeView.DrawNode 노드 태그 및 사용자 지정 선택 수동으로 강조 표시 하는 이벤트 그립니다. 선택 되지 않은 노드는 사용자 지정할이 필요가 없습니다. 이러한 경우는 DrawDefault 속성이 true 운영 체제에서 그려질 수 있도록 합니다.

전체 예제를 참조 하세요.를 DrawTreeNodeEventArgs 개요 항목을 참조 합니다.

   // 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

설명

이 속성을 사용 하 여 확인 여부를 TreeNode 그릴 개체가 특정 상태에 있습니다. 이 속성 노드에 대 한 기본 상태 정보를 제공합니다. 예를 들어,이 속성을를 사용 하 여 노드 선택, 옵션을 선택 또는 초점을 맞춘 결정할 수 있습니다. 자세한 내용을 보려면 해야 할 경우를 통해 노드를 검색 합니다 Node 속성입니다. 예를 들어, 노드가 확장 되었는지 여부를 확인 하려면 노드를 검색 하며 확인 된 TreeNode.IsExpanded 속성입니다.

적용 대상

추가 정보