Partager via


DrawToolTipEventArgs.ToolTipText Propriété

Définition

Obtient le texte du ToolTip 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 moment où l’événement Draw se produit.

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 de la DrawBorder méthode et l’utilisation des propriétés, ToolTipTextet Graphics les Boundspropriétés. Consultez la vue d’ensemble de la DrawToolTipEventArgs 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 info-bulle. Si vous souhaitez que le texte 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