DrawToolTipEventArgs.Graphics Propriété

Définition

Obtient la surface graphique utilisée pour dessiner 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

Valeur de propriété

Graphics sur lequel dessiner ToolTip.

Exemples

L’exemple de code suivant montre comment personnaliser le dessin .ToolTip L’exemple crée un ToolTip et l’associe à trois Button contrôles situés sur le Form. L’exemple définit la propriété sur OwnerDraw true et gère l’événement Draw . Dans le Draw gestionnaire d’événements, le ToolTip est dessiné différemment en fonction du ToolTip bouton affiché comme indiqué par la DrawToolTipEventArgs.AssociatedControl propriété .

L’extrait de code ci-dessous illustre l’utilisation des DrawText méthodes et DrawBackground et de la Graphics propriété . Consultez la vue d’ensemble DrawToolTipEventArgs de la classe pour obtenir l’exemple de code complet.

// 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)

Remarques

Vous utilisez l’objet Graphics pour personnaliser le dessin de certains aspects visuels d’un ToolTip. Par exemple, vous pouvez dessiner votre propre arrière-plan d’info-bulle à l’aide de la Graphics.FillRectangle méthode .

Tout dessin personnalisé effectué en dehors du rectangle spécifié par la Bounds propriété n’apparaît pas. Vous pouvez augmenter les limites du ToolTip avant qu’il ne s’affiche en gérant l’événement ToolTip.Popup .

La DrawToolTipEventArgs classe fournit également les DrawBackgroundméthodes , DrawText et DrawBorder pour dessiner des parties individuelles de dans ToolTip la manière standard utilisée par le système d’exploitation. Vous pouvez utiliser ces méthodes, ainsi que les Graphics méthodes d’objet, pour créer certaines parties de votre info-bulle standard, tout en personnalisant d’autres parties.

S’applique à