TreeViewDrawMode 枚举

定义

定义表示 TreeView 的绘制方法的常数。Defines constants that represent the ways a TreeView can be drawn.

public enum class TreeViewDrawMode
public enum TreeViewDrawMode
type TreeViewDrawMode = 
Public Enum TreeViewDrawMode
继承
TreeViewDrawMode

字段

Normal 0

TreeView 由操作系统绘制。The TreeView is drawn by the operating system.

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

注解

此枚举由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.

适用于

另请参阅