DrawToolTipEventArgs.Graphics Propriedade

Definição

Obtém a superfície de elementos gráficos usada para desenhar o 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 da propriedade

A Graphics na qual desenhar o ToolTip.

Exemplos

O exemplo de código a seguir demonstra como desenhar ToolTipo personalizado. O exemplo cria um ToolTip e o associa a três Button controles localizados no Form. O exemplo define a OwnerDraw propriedade como true e manipula o Draw evento . Draw No manipulador de eventos, o ToolTip é personalizado desenhado de forma diferente, dependendo do botão para o qual o ToolTip está sendo exibido, conforme indicado pela DrawToolTipEventArgs.AssociatedControl propriedade .

O trecho de código abaixo demonstra o uso dos DrawText métodos e DrawBackground e o uso da Graphics propriedade . Consulte a visão geral da DrawToolTipEventArgs classe para obter o exemplo 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)

Comentários

Use o Graphics objeto para personalizar o desenho de determinados aspectos visuais de um ToolTip. Por exemplo, você pode desenhar sua própria tela de fundo da Dica de Ferramenta usando o Graphics.FillRectangle método .

Qualquer desenho personalizado feito fora do retângulo especificado pela Bounds propriedade não será exibido. Você pode aumentar os limites do ToolTip antes que ele seja mostrado manipulando o ToolTip.Popup evento.

A DrawToolTipEventArgs classe também fornece os DrawBackgroundmétodos e DrawTextDrawBorder para desenhar partes individuais do da ToolTip maneira padrão usada pelo sistema operacional. Você pode usar esses métodos, juntamente com os Graphics métodos de objeto, para tornar algumas partes do seu ToolTip padrão, enquanto personaliza outras partes.

Aplica-se a