TreeViewDrawMode Enumeración

Definición

Define las constantes que representan cómo se puede dibujar un control TreeView.Defines constants that represent the ways a TreeView can be drawn.

public enum class TreeViewDrawMode
public enum TreeViewDrawMode
type TreeViewDrawMode = 
Public Enum TreeViewDrawMode
Herencia
TreeViewDrawMode

Campos

Normal 0

El sistema operativo ha dibujado el control TreeView.The TreeView is drawn by the operating system.

OwnerDrawAll 2

Se dibujan manualmente todos los elementos de un nodo TreeView, incluso los iconos, casillas, los signos de más y menos, y las líneas que conectan los nodos.All elements of a TreeView node are drawn manually, including icons, checkboxes, plus and minus signs, and lines connecting the nodes.

OwnerDrawText 1

Se dibuja manualmente la parte de la etiqueta de los nodos TreeView.The label portion of the TreeView nodes are drawn manually. El sistema operativo dibuja otros elementos de nodo, incluyendo los iconos, casillas, los signos de más y menos y las líneas que conectan los nodos.Other node elements are drawn by the operating system, including icons, checkboxes, plus and minus signs, and lines connecting the nodes.

Ejemplos

En el ejemplo de código siguiente se muestra cómo TreeView personalizar un control mediante su funcionalidad de dibujo de propietario.The following code example demonstrates how to customize a TreeView control using its owner-draw capability. El TreeView control en el ejemplo muestra etiquetas de nodo opcionales junto con las etiquetas de nodo estándar.The TreeView control in the example displays optional node tags alongside the standard node labels. Las etiquetas de nodo se especifican mediante la TreeNode.Tag propiedad.Node tags are specified using the TreeNode.Tag property. El TreeView control también utiliza colores personalizados, incluido un color de resaltado personalizado.The TreeView control also uses custom colors, including a custom highlight color.

Puede personalizar la mayoría de los TreeView colores estableciendo las propiedades de color, pero el color de resaltado de la selección no está disponible como una propiedad.You can customize most of the TreeView colors by setting color properties, but the selection highlight color is not available as a property. Además, el rectángulo de resaltado de selección predeterminado solo se extiende alrededor de una etiqueta de nodo.Additionally, the default selection highlight rectangle extends only around a node label. El dibujo del propietario debe utilizarse para dibujar las etiquetas de nodo y para dibujar un rectángulo de resaltado personalizado lo suficientemente grande como para incluir una etiqueta de nodo.Owner drawing must be used to draw the node tags and to draw a customized highlight rectangle large enough to include a node tag.

Para obtener el ejemplo completo, vea TreeView.DrawNode el tema de referencia.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

Comentarios

Esta enumeración la usa la TreeView.DrawMode propiedad para indicar si los nodos o las etiquetas de nodo de TreeView un son dibujados por el propietario.This enumeration is used by the TreeView.DrawMode property to indicate whether the nodes or node-labels of a TreeView are owner-drawn. Para obtener más información, vea el evento TreeView.DrawNode.For more information, see the TreeView.DrawNode event.

Se aplica a

Consulte también: