Evaluar y enviar comentarios
Contraer todo/Expandir todo Contraer todo
Esta página es específica de
Microsoft Visual Studio 2008/.NET Framework 3.5

Hay además otras versiones disponibles para:
Biblioteca de clases de .NET Framework
DrawMode (Enumeración)

Actualización: noviembre 2007

Especifica cómo se dibujan los elementos de un control.

Espacio de nombres:  System.Windows.Forms
Ensamblado:  System.Windows.Forms (en System.Windows.Forms.dll)
Visual Basic (Declaración)
Public Enumeration DrawMode
Visual Basic (Uso)
Dim instance As DrawMode
C#
public enum DrawMode
Visual C++
public enum class DrawMode
J#
public enum DrawMode
JScript
public enum DrawMode
Nombre de miembroDescripción
NormalEl sistema operativo dibuja todos los elementos de un control y tienen el mismo tamaño.
OwnerDrawFixedTodos los elementos del control se dibujan manualmente y tienen el mismo tamaño.
OwnerDrawVariableTodos los elementos del control se dibujan manualmente, y pueden ser de distinto tamaño.

Utilizan esta enumeración miembros como DrawMode en las clases ListBox, CheckedListBox y ComboBox.

Se puede reemplazar el dibujo de algunos controles o de ciertos elementos. Esta enumeración se emplea para especificar si el sistema operativo dibuja un control o si es el propio código el que controla el dibujado del control.

81d2a933.alert_note(es-es,VS.90).gifNota:

La clase CheckedListBox sólo admite DrawMode..::.Normal; los modos de dibujo propietarios se pasan por alto.

Para obtener más información sobre cómo utilizar la enumeración DrawMode, vea los eventos MeasureItem y DrawItem, y la propiedad ItemHeight.

En el siguiente ejemplo se muestra la forma de crear elementos ListBox dibujados por el propietario. En el código se utiliza la propiedad DrawMode para especificar que los elementos dibujados tengan un tamaño fijo y que el evento DrawItem realice el dibujo de cada uno de los elementos en ListBox. En el código de ejemplo se utilizan las propiedades y los métodos de la clase DrawItemEventArgs que se ha pasado como parámetro al controlador de eventos para dibujar los elementos. En este ejemplo se supone que se ha agregado un control ListBox denominado listBox1 a un formulario y que el controlador de eventos definido en el código de ejemplo controla el evento DrawItem. En el ejemplo se supone también que se han agregado elementos a ListBox con el texto "Apple", "Orange" y "Plum", en ese orden.

Visual Basic
Private WithEvents ListBox1 As New ListBox()

Private Sub InitializeListBox() 
    ListBox1.Items.AddRange(New Object() _
        {"Red Item", "Orange Item", "Purple Item"})
    ListBox1.Location = New System.Drawing.Point(81, 69)
    ListBox1.Size = New System.Drawing.Size(120, 95)
    ListBox1.DrawMode = DrawMode.OwnerDrawFixed
    Controls.Add(ListBox1)

End Sub

Private Sub ListBox1_DrawItem(ByVal sender As Object, _
 ByVal e As System.Windows.Forms.DrawItemEventArgs) _
 Handles ListBox1.DrawItem

    ' Draw the background of the ListBox control for each item.
    e.DrawBackground()

    ' Define the default color of the brush as black.
    Dim myBrush As Brush = Brushes.Black

    ' Determine the color of the brush to draw each item based on   
    ' the index of the item to draw.
    Select Case e.Index
        Case 0
            myBrush = Brushes.Red
        Case 1
            myBrush = Brushes.Orange
        Case 2
            myBrush = Brushes.Purple
    End Select

    ' Draw the current item text based on the current 
    ' Font and the custom brush settings.
    e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), _
        e.Font, myBrush, e.Bounds, StringFormat.GenericDefault)

    ' If the ListBox has focus, draw a focus rectangle around  _ 
    ' the selected item.
    e.DrawFocusRectangle()
End Sub
C#
private ListBox ListBox1 = new ListBox();
private void InitializeListBox()
{
    ListBox1.Items.AddRange(new Object[] 
        { "Red Item", "Orange Item", "Purple Item" });
    ListBox1.Location = new System.Drawing.Point(81, 69);
    ListBox1.Size = new System.Drawing.Size(120, 95);
    ListBox1.DrawMode = DrawMode.OwnerDrawFixed;
    ListBox1.DrawItem += new DrawItemEventHandler(ListBox1_DrawItem);
    Controls.Add(ListBox1);
}

private void ListBox1_DrawItem(object sender, 
    System.Windows.Forms.DrawItemEventArgs e)
{
    // Draw the background of the ListBox control for each item.
    e.DrawBackground();
    // Define the default color of the brush as black.
    Brush myBrush = Brushes.Black;

    // Determine the color of the brush to draw each item based 
    // on the index of the item to draw.
    switch (e.Index)
    {
        case 0:
            myBrush = Brushes.Red;
            break;
        case 1:
            myBrush = Brushes.Orange;
            break;
        case 2:
            myBrush = Brushes.Purple;
            break;
    }

    // Draw the current item text based on the current Font 
    // and the custom brush settings.
    e.Graphics.DrawString(ListBox1.Items[e.Index].ToString(), 
        e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
    // If the ListBox has focus, draw a focus rectangle around the selected item.
    e.DrawFocusRectangle();
}

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

.NET Framework

Compatible con: 3.5, 3.0, 2.0, 1.1, 1.0
Contenido de la comunidad   ¿Qué es Community Content?
Agregar contenido nuevo RSS  Anotaciones
Processing
© 2012 Microsoft. Reservados todos los derechos. Términos de uso | Marcas Registradas | Privacidad
Page view tracker