DrawToolTipEventArgs.Graphics Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient l’aire graphique utilisée pour dessiner le 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é
Sur Graphics lequel dessiner le ToolTip.
Exemples
L’exemple de code suivant montre comment dessiner ToolTiple dessin personnalisé . L’exemple crée et ToolTip l’associe à trois Button contrôles situés sur le Form. L’exemple montre comment définir la OwnerDraw propriété sur true et gérer l’événement Draw . Dans le Draw gestionnaire d’événements, l’objet ToolTip est dessiné différemment en fonction du bouton pour lequel il ToolTip est affiché, comme indiqué par la DrawToolTipEventArgs.AssociatedControl propriété.
L’extrait de code ci-dessous illustre l’utilisation des DrawText méthodes et DrawBackground de la Graphics propriété. Consultez la vue d’ensemble de la DrawToolTipEventArgs 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 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é ne s’affiche pas. Vous pouvez augmenter les limites de l’événement ToolTip avant qu’elle ne soit affichée en gérant l’événement ToolTip.Popup .
La DrawToolTipEventArgs classe fournit également les méthodes DrawText et DrawBorder les DrawBackgroundméthodes permettant de dessiner des parties individuelles de la ToolTip méthode 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.