DrawToolTipEventArgs.Graphics Propiedad

Definición

Obtiene la superficie de gráficos utilizada para dibujar ToolTip.

public:
 property System::Drawing::Graphics ^ Graphics { System::Drawing::Graphics ^ get(); };
public System.Drawing.Graphics Graphics { get; }
member this.Graphics : System.Drawing.Graphics
Public ReadOnly Property Graphics As Graphics

Valor de propiedad

Graphics donde se va a dibujar ToolTip.

Ejemplos

En el ejemplo de código siguiente se muestra cómo dibujar de forma personalizada .ToolTip En el ejemplo se crea un ToolTip objeto y se asocia a tres Button controles ubicados en .Form En el ejemplo se establece la OwnerDraw propiedad en true y se controla el Draw evento. En el Draw controlador de eventos, ToolTip el elemento se dibuja de forma diferente en función del botón para el que se muestra el ToolTip valor indicado por la DrawToolTipEventArgs.AssociatedControl propiedad .

El fragmento de código siguiente muestra el uso de los DrawText métodos y DrawBackground y el uso de la Graphics propiedad . Consulte la información general de la DrawToolTipEventArgs clase para obtener el ejemplo de código completo.

// Draw a custom 3D border if the ToolTip is for button1.
if ( e->AssociatedControl == button1 )
{
   // Draw the standard background.
   e->DrawBackground();
   
   // Draw the custom border to appear 3-dimensional.
   array<Point>^ temp1 = {Point(0,e->Bounds.Height - 1),Point(0,0),Point(e->Bounds.Width - 1,0)};
   e->Graphics->DrawLines( SystemPens::ControlLightLight, temp1 );
   array<Point>^ temp2 = {Point(0,e->Bounds.Height - 1),Point(e->Bounds.Width - 1,e->Bounds.Height - 1),Point(e->Bounds.Width - 1,0)};
   e->Graphics->DrawLines( SystemPens::ControlDarkDark, temp2 );
   
   // Specify custom text formatting flags.
   TextFormatFlags sf = static_cast<TextFormatFlags>(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter | TextFormatFlags::NoFullWidthCharacterBreak);
   
   // Draw the standard text with customized formatting options.
   e->DrawText( sf );
}
// Draw a custom 3D border if the ToolTip is for button1.
if (e.AssociatedControl == button1)
{
    // Draw the standard background.
    e.DrawBackground();

    // Draw the custom border to appear 3-dimensional.
    e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
        new Point (0, e.Bounds.Height - 1), 
        new Point (0, 0), 
        new Point (e.Bounds.Width - 1, 0)
    });
    e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
        new Point (0, e.Bounds.Height - 1), 
        new Point (e.Bounds.Width - 1, e.Bounds.Height - 1), 
        new Point (e.Bounds.Width - 1, 0)
    });

    // Specify custom text formatting flags.
    TextFormatFlags sf = TextFormatFlags.VerticalCenter |
                         TextFormatFlags.HorizontalCenter |
                         TextFormatFlags.NoFullWidthCharacterBreak;

    // Draw the standard text with customized formatting options.
    e.DrawText(sf);
}
' Draw a custom 3D border if the ToolTip is for button1.
If (e.AssociatedControl Is button1) Then
    ' Draw the standard background.
    e.DrawBackground()

    ' Draw the custom border to appear 3-dimensional.
    e.Graphics.DrawLines( _
        SystemPens.ControlLightLight, New Point() { _
        New Point(0, e.Bounds.Height - 1), _
        New Point(0, 0), _
        New Point(e.Bounds.Width - 1, 0)})
    e.Graphics.DrawLines( _
        SystemPens.ControlDarkDark, New Point() { _
        New Point(0, e.Bounds.Height - 1), _
        New Point(e.Bounds.Width - 1, e.Bounds.Height - 1), _
        New Point(e.Bounds.Width - 1, 0)})

    ' Specify custom text formatting flags.
    Dim sf As TextFormatFlags = TextFormatFlags.VerticalCenter Or _
                         TextFormatFlags.HorizontalCenter Or _
                         TextFormatFlags.NoFullWidthCharacterBreak

    ' Draw standard text with customized formatting options.
    e.DrawText(sf)

Comentarios

Use el Graphics objeto para personalizar el dibujo de determinados aspectos visuales de un ToolTipobjeto . Por ejemplo, puede dibujar su propio fondo de información sobre herramientas mediante el Graphics.FillRectangle método .

No se mostrará ningún dibujo personalizado que se realice fuera del rectángulo especificado por la Bounds propiedad . Puede aumentar los límites de antes ToolTip de que se muestre controlando el ToolTip.Popup evento.

La DrawToolTipEventArgs clase también proporciona los DrawBackgroundmétodos , DrawText y DrawBorder para dibujar partes individuales de en ToolTip la forma estándar utilizada por el sistema operativo. Puede usar estos métodos, junto con los Graphics métodos de objeto, para crear algunas partes del estándar toolTip, al mismo tiempo que personaliza otras partes.

Se aplica a