TreeViewDrawMode TreeViewDrawMode TreeViewDrawMode TreeViewDrawMode Enum

定義

TreeView の描画方法を表す定数を定義します。Defines constants that represent the ways a TreeView can be drawn.

public enum class TreeViewDrawMode
public enum TreeViewDrawMode
type TreeViewDrawMode = 
Public Enum TreeViewDrawMode
継承
TreeViewDrawModeTreeViewDrawModeTreeViewDrawModeTreeViewDrawMode

フィールド

Normal Normal Normal Normal 0

TreeView はオペレーティング システムによって描画されます。The TreeView is drawn by the operating system.

OwnerDrawAll OwnerDrawAll OwnerDrawAll OwnerDrawAll 2

アイコン、チェック ボックス、プラス記号とマイナス記号、ノードを接続する線などを含め、TreeView ノードのすべての要素は手動で描画されます。All elements of a TreeView node are drawn manually, including icons, checkboxes, plus and minus signs, and lines connecting the nodes.

OwnerDrawText OwnerDrawText OwnerDrawText OwnerDrawText 1

TreeView ノードのラベル部分は手動で描画されます。The label portion of the TreeView nodes are drawn manually. それ以外のノード要素、たとえばアイコン、チェック ボックス、プラス記号とマイナス記号、ノードを接続する線などは、オペレーティング システムにより描画されます。Other node elements are drawn by the operating system, including icons, checkboxes, plus and minus signs, and lines connecting the nodes.

オーナー描画機能を使用してTreeViewコントロールをカスタマイズする方法を次のコード例に示します。The following code example demonstrates how to customize a TreeView control using its owner-draw capability. この例のコントロールでは、標準のノードラベルと共にオプションのノードタグが表示されます。 TreeViewThe TreeView control in the example displays optional node tags alongside the standard 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 、リファレンストピックを参照してください。For the complete example, see the TreeView.DrawNode reference topic.

TreeViewOwnerDraw()
{
   tagFont = gcnew System::Drawing::Font( "Helvetica",8,FontStyle::Bold );

   // Create and initialize the TreeView control.
   myTreeView = gcnew TreeView;
   myTreeView->Dock = DockStyle::Fill;
   myTreeView->BackColor = Color::Tan;
   myTreeView->CheckBoxes = true;
   
   // Add nodes to the TreeView control.
   TreeNode^ node;
   for ( int x = 1; x < 4; ++x )
   {
      // Add a root node to the TreeView control.
      node = myTreeView->Nodes->Add( String::Format( "Task {0}", x ) );
      for ( int y = 1; y < 4; ++y )
      {
         // Add a child node to the root node.
         node->Nodes->Add( String::Format( "Subtask {0}", y ) );
      }
   }
   myTreeView->ExpandAll();
   
   // Add tags containing alert messages to a few nodes 
   // and set the node background color to highlight them.
   myTreeView->Nodes[ 1 ]->Nodes[ 0 ]->Tag = "urgent!";
   myTreeView->Nodes[ 1 ]->Nodes[ 0 ]->BackColor = Color::Yellow;
   myTreeView->SelectedNode = myTreeView->Nodes[ 1 ]->Nodes[ 0 ];
   myTreeView->Nodes[ 2 ]->Nodes[ 1 ]->Tag = "urgent!";
   myTreeView->Nodes[ 2 ]->Nodes[ 1 ]->BackColor = Color::Yellow;
   
   // Configure the TreeView control for owner-draw and add
   // a handler for the DrawNode event.
   myTreeView->DrawMode = TreeViewDrawMode::OwnerDrawText;
   myTreeView->DrawNode += gcnew DrawTreeNodeEventHandler( this, &TreeViewOwnerDraw::myTreeView_DrawNode );
   
   // Add a handler for the MouseDown event so that a node can be 
   // selected by clicking the tag text as well as the node text.
   myTreeView->MouseDown += gcnew MouseEventHandler( this, &TreeViewOwnerDraw::myTreeView_MouseDown );
   
   // Initialize the form and add the TreeView control to it.
   this->ClientSize = System::Drawing::Size( 292, 273 );
   this->Controls->Add( myTreeView );
}
public TreeViewOwnerDraw()
{
    // Create and initialize the TreeView control.
    myTreeView = new TreeView();
    myTreeView.Dock = DockStyle.Fill;
    myTreeView.BackColor = Color.Tan;
    myTreeView.CheckBoxes = true;

    // Add nodes to the TreeView control.
    TreeNode node;
    for (int x = 1; x < 4; ++x)
    {
        // Add a root node to the TreeView control.
        node = myTreeView.Nodes.Add(String.Format("Task {0}", x));
        for (int y = 1; y < 4; ++y)
        {
            // Add a child node to the root node.
            node.Nodes.Add(String.Format("Subtask {0}", y));
        }
    }
    myTreeView.ExpandAll();

    // Add tags containing alert messages to a few nodes 
    // and set the node background color to highlight them.
    myTreeView.Nodes[1].Nodes[0].Tag = "urgent!";
    myTreeView.Nodes[1].Nodes[0].BackColor = Color.Yellow;
    myTreeView.SelectedNode = myTreeView.Nodes[1].Nodes[0];
    myTreeView.Nodes[2].Nodes[1].Tag = "urgent!";
    myTreeView.Nodes[2].Nodes[1].BackColor = Color.Yellow;

    // Configure the TreeView control for owner-draw and add
    // a handler for the DrawNode event.
    myTreeView.DrawMode = TreeViewDrawMode.OwnerDrawText;
    myTreeView.DrawNode += 
        new DrawTreeNodeEventHandler(myTreeView_DrawNode);

    // Add a handler for the MouseDown event so that a node can be 
    // selected by clicking the tag text as well as the node text.
    myTreeView.MouseDown += new MouseEventHandler(myTreeView_MouseDown);

    // Initialize the form and add the TreeView control to it.
    this.ClientSize = new Size(292, 273);
    this.Controls.Add(myTreeView);
}
Public Sub New()

    ' Create and initialize the TreeView control.
    myTreeView = New TreeView()
    myTreeView.Dock = DockStyle.Fill
    myTreeView.BackColor = Color.Tan
    myTreeView.CheckBoxes = True
    
    ' Add nodes to the TreeView control.
    Dim node As TreeNode
    Dim x As Integer
    For x = 1 To 3

        ' Add a root node to the TreeView control.
        node = myTreeView.Nodes.Add(String.Format("Task {0}", x))
        Dim y As Integer
        For y = 1 To 3 

            ' Add a child node to the root node.
            node.Nodes.Add(String.Format("Subtask {0}", y))
        Next y
    Next x
    myTreeView.ExpandAll()
    
    ' Add tags containing alert messages to a few nodes 
    ' and set the node background color to highlight them.
    myTreeView.Nodes(1).Nodes(0).Tag = "urgent!"
    myTreeView.Nodes(1).Nodes(0).BackColor = Color.Yellow
    myTreeView.SelectedNode = myTreeView.Nodes(1).Nodes(0)
    myTreeView.Nodes(2).Nodes(1).Tag = "urgent!"
    myTreeView.Nodes(2).Nodes(1).BackColor = Color.Yellow
    
    ' Configure the TreeView control for owner-draw.
    myTreeView.DrawMode = TreeViewDrawMode.OwnerDrawText

    ' Add a handler for the MouseDown event so that a node can be 
    ' selected by clicking the tag text as well as the node text.
    AddHandler myTreeView.MouseDown, AddressOf myTreeView_MouseDown
    
    ' Initialize the form and add the TreeView control to it.
    Me.ClientSize = New Size(292, 273)
    Me.Controls.Add(myTreeView)
End Sub 'New

注釈

この列挙体は、 TreeView.DrawMode TreeViewのノードまたはノードラベルがオーナー描画かどうかを示すために、プロパティによって使用されます。This enumeration is used by the TreeView.DrawMode property to indicate whether the nodes or node-labels of a TreeView are owner-drawn. 詳細については、TreeView.DrawNode イベントを参照してください。For more information, see the TreeView.DrawNode event.

適用対象

こちらもご覧ください