共用方式為


TreeViewDrawMode 列舉

定義

定義常數,表示可描繪 TreeView 的方式。

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

欄位

Normal 0

TreeView 由作業系統描繪。

OwnerDrawAll 2

TreeView 節點的所有項目都是手動描繪的,包含圖示、核取方塊、加號和減號,以及連接節點的線條。

OwnerDrawText 1

TreeView 節點的標籤部分是手動描繪的。 其他節點項目則是由作業系統描繪,包含圖示、核取方塊、加號和減號,以及連接節點的線條。

範例

下列程式碼範例示範如何使用其擁有者繪製功能來自訂 TreeView 控制項。 範例 TreeView 中的控制項會顯示選擇性節點標籤以及標準節點標籤。 節點標籤是使用 屬性來 TreeNode.Tag 指定。 控制項 TreeView 也會使用自訂色彩,包括自訂醒目提示色彩。

您可以藉由設定色彩屬性來自訂大部分 TreeView 的色彩,但選取範圍醒目提示色彩無法當做屬性使用。 此外,預設選取範圍醒目提示矩形只會在節點標籤周圍延伸。 擁有者繪圖必須用來繪製節點標籤,並繪製足以包含節點標籤的自訂醒目提示矩形。

如需完整的範例,請參閱 TreeView.DrawNode 參考主題。

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 節點或節點標籤是否為擁有者繪製。 如需詳細資訊,請參閱 TreeView.DrawNode 事件。

適用於

另請參閱