TreeView.DrawMode Propriedade

Definição

Obtém ou define o modo no qual o controle é desenhado.

public:
 property System::Windows::Forms::TreeViewDrawMode DrawMode { System::Windows::Forms::TreeViewDrawMode get(); void set(System::Windows::Forms::TreeViewDrawMode value); };
public System.Windows.Forms.TreeViewDrawMode DrawMode { get; set; }
member this.DrawMode : System.Windows.Forms.TreeViewDrawMode with get, set
Public Property DrawMode As TreeViewDrawMode

Valor da propriedade

Um dos valores de TreeViewDrawMode. O padrão é Normal.

Exceções

O valor da propriedade não é um valor TreeViewDrawMode válido.

Exemplos

O exemplo de código a seguir demonstra como personalizar um TreeView controle usando o desenho do proprietário. O TreeView controle no exemplo exibe marcas de nó opcionais junto com os rótulos de nó padrão. As marcas de nó são especificadas usando a TreeNode.Tag propriedade . O TreeView controle também usa cores personalizadas, que incluem uma cor de realce personalizada.

Você pode personalizar a TreeView maioria das cores definindo propriedades de cor, mas a cor de realce da seleção não está disponível como uma propriedade. Além disso, o retângulo de realce de seleção padrão se estende apenas em torno de um rótulo de nó. O desenho do proprietário deve ser usado para desenhar as marcas de nó e desenhar um retângulo de realce personalizado grande o suficiente para incluir uma marca de nó.

Para obter o exemplo completo, consulte o DrawNode tópico de referência.

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

Comentários

Os nós de um TreeView normalmente são desenhados pelo sistema operacional. A DrawMode propriedade permite personalizar a aparência dos nós. Para fazer isso, defina DrawMode como TreeViewDrawMode.OwnerDrawAll ou TreeViewDrawMode.OwnerDrawText e forneça um manipulador para o DrawNode evento. Isso é chamado de desenho de proprietário.

Aplica-se a

Confira também