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

注釈

この列挙は、 クラスの StateDrawTreeNodeEventArgs プロパティによって使用されます。 詳細については、TreeView.DrawNode イベントを参照してください。

適用対象

こちらもご覧ください