DrawToolTipEventArgs.ToolTipText Propriété

Définition

Obtient le texte de ToolTip qui est en train d'être dessiné.

public:
 property System::String ^ ToolTipText { System::String ^ get(); };
public string ToolTipText { get; }
public string? ToolTipText { get; }
member this.ToolTipText : string
Public ReadOnly Property ToolTipText As String

Valeur de propriété

Texte associé au ToolTip lorsque l'événement Draw se produit.

Exemples

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

L’extrait de code ci-dessous illustre l’utilisation de la DrawBorder méthode et l’utilisation des Boundspropriétés , ToolTipTextet Graphics . Consultez la vue d’ensemble DrawToolTipEventArgs de la classe pour obtenir l’exemple de code complet.

// Draw a custom background and text if the ToolTip is for button2.
else

// Draw a custom background and text if the ToolTip is for button2.
if ( e->AssociatedControl == button2 )
{
   // Draw the custom background.
   e->Graphics->FillRectangle( SystemBrushes::ActiveCaption, e->Bounds );
   
   // Draw the standard border.
   e->DrawBorder();
   
   // Draw the custom text.
   // The using block will dispose the StringFormat automatically.
   StringFormat^ sf = gcnew StringFormat;
   try
   {
      sf->Alignment = StringAlignment::Center;
      sf->LineAlignment = StringAlignment::Center;
      sf->HotkeyPrefix = System::Drawing::Text::HotkeyPrefix::None;
      sf->FormatFlags = StringFormatFlags::NoWrap;
      System::Drawing::Font^ f = gcnew System::Drawing::Font( "Tahoma",9 );
      try
      {
         e->Graphics->DrawString( e->ToolTipText, f, SystemBrushes::ActiveCaptionText, e->Bounds, sf );
      }
      finally
      {
         if ( f )
            delete safe_cast<IDisposable^>(f);
      }

   }
   finally
   {
      if ( sf )
         delete safe_cast<IDisposable^>(sf);
   }
}
// Draw a custom background and text if the ToolTip is for button2.
else if (e.AssociatedControl == button2)
{
    // Draw the custom background.
    e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);

    // Draw the standard border.
    e.DrawBorder();

    // Draw the custom text.
    // The using block will dispose the StringFormat automatically.
    using (StringFormat sf = new StringFormat())
    {
        sf.Alignment = StringAlignment.Center;
        sf.LineAlignment = StringAlignment.Center;
        sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
        sf.FormatFlags = StringFormatFlags.NoWrap;
        using (Font f = new Font("Tahoma", 9))
        {
            e.Graphics.DrawString(e.ToolTipText, f, 
                SystemBrushes.ActiveCaptionText, e.Bounds, sf);
        }
    }
}
ElseIf (e.AssociatedControl Is button2) Then
    ' Draw a custom background and text if the ToolTip is for button2.

    ' Draw the custom background.
    e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds)

    ' Draw the standard border.
    e.DrawBorder()

    ' Draw the custom text.
    Dim sf As StringFormat = New StringFormat
    Try
        sf.Alignment = StringAlignment.Center
        sf.LineAlignment = StringAlignment.Center
        sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None
        sf.FormatFlags = StringFormatFlags.NoWrap

        Dim f As Font = New Font("Tahoma", 9)
        Try
            e.Graphics.DrawString(e.ToolTipText, f, _
                SystemBrushes.ActiveCaptionText, _
                RectangleF.op_Implicit(e.Bounds), sf)
        Finally
            f.Dispose()
        End Try
    Finally
        sf.Dispose()
    End Try

Remarques

En règle générale, vous utilisez la ToolTipText propriété pour déterminer le texte de l’info-bulle lorsque vous dessinez votre info-bulle personnalisé. Vous pouvez utiliser la Graphics.DrawString méthode pour personnaliser le dessin du texte de l’info-bulle. Si vous souhaitez que le texte de l’info-bulle soit dessiné à l’aide du style spécifié par le système, utilisez la DrawText méthode . La valeur de texte provient de la valeur passée à la SetToolTip méthode de la ToolTip classe .

S’applique à

Voir aussi