TreeNodeStates 列挙型

定義

TreeNode に設定できる状態を表す定数を定義します。Defines constants that represent the possible states of a TreeNode.

この列挙型には FlagsAttribute 属性があり、メンバー値ではビットごとの組み合わせを使用できます。

public enum class TreeNodeStates
[System.Flags]
public enum TreeNodeStates
type TreeNodeStates = 
Public Enum TreeNodeStates
継承
TreeNodeStates
属性

フィールド

Checked 8

ノードがチェックされています。The node is checked.

Default 32

ノードが既定の状態です。The node is in its default state.

Focused 16

ノードにフォーカスがあります。The node has focus.

Grayed 2

ノードが無効です。The node is disabled.

Hot 64

ノードがホットです。The node is hot. この状態は、HotTracking プロパティが true に設定され、マウス ポインターがノードの上にあるときに発生します。This state occurs when the HotTracking property is set to true and the mouse pointer is over the node.

Indeterminate 256

ノードが中間状態です。The node in an indeterminate state.

Marked 128

ノードがマークされています。The node is marked.

Selected 1

ノードが選択されています。The node is selected.

ShowKeyboardCues 512

ノードにショートカット キーが示されます。The node should indicate a keyboard shortcut.

オーナー描画を使用してTreeViewコントロールをカスタマイズする方法を次の例に示します。The following example demonstrates how to customize a TreeView control using owner drawing. この例のコントロールでは、通常のノードラベルと共にオプションのノードタグが表示されます。 TreeViewThe TreeView control in the example displays optional node tags alongside the normal node labels. ノードタグは、 TreeNode.Tagプロパティを使用して指定します。Node tags are specified using the TreeNode.Tag property. コントロールTreeViewでは、カスタムの強調表示色など、カスタムの色も使用します。The TreeView control also uses custom colors, including a custom highlight color.

色のプロパティを設定するTreeViewことで、ほとんどの色をカスタマイズできますが、選択範囲の強調表示の色はプロパティとして使用できません。You can customize most of the TreeView colors by setting color properties, but the selection highlight color is not available as a property. また、既定の選択の強調表示四角形は、ノードラベルの周囲のみを拡張します。Additionally, the default selection highlight rectangle extends only around a node label. ノードタグを描画し、ノードタグを含めるのに十分な大きさのカスタマイズされた強調表示領域を描画するには、オーナー描画を使用する必要があります。Owner drawing must be used to draw the node tags and to draw a customized highlight rectangle large enough to include a node tag.

この例では、 TreeView.DrawNodeイベントのハンドラーは、 DrawTreeNodeEventArgsクラスのメソッドを呼び出すことにより、選択されていないノードを描画します。In the example, a handler for the TreeView.DrawNode event draws unselected nodes by calling methods of the DrawTreeNodeEventArgs class. これらのメソッドは、カスタマイズをTreeView必要としない要素の既定の外観を提供します。These methods provide the default appearance for TreeView elements that do not need customization. このハンドラーは、ノードタグとカスタム選択の強調表示を手動で描画します。The handler draws the node tags and the custom selection highlight manually.

完全な例についてはTreeView.DrawNode 、リファレンストピックを参照してください。For the complete example, see the TreeView.DrawNode reference topic.

   // 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クラスのプロパティによって使用されます。This enumeration is used by the State property of the DrawTreeNodeEventArgs class. 詳細については、TreeView.DrawNode イベントを参照してください。For more information, see the TreeView.DrawNode event.

適用対象

こちらもご覧ください