Condividi tramite


DrawToolTipEventArgs.ToolTipText Proprietà

Definizione

Ottiene il testo per l'oggetto ToolTip da disegnare.

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

Valore della proprietà

Testo associato a ToolTip quando si verifica l'evento Draw .

Esempio

Nell'esempio di codice seguente viene illustrato come disegnare l'oggetto ToolTippersonalizzato. L'esempio crea un oggetto ToolTip e lo associa a tre Button controlli che si trovano nell'oggetto Form. Nell'esempio la OwnerDraw proprietà viene impostata su true e viene gestito l'evento Draw . Nel gestore eventi l'oggetto DrawToolTip viene disegnato in modo diverso a seconda del pulsante ToolTip per cui viene visualizzato come indicato dalla DrawToolTipEventArgs.AssociatedControl proprietà .

L'estratto di codice seguente illustra l'uso del DrawBorder metodo e l'uso delle Boundsproprietà , ToolTipTexte Graphics . Vedere la panoramica della DrawToolTipEventArgs classe per l'esempio di codice completo.

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

Commenti

In genere si utilizza la ToolTipText proprietà per determinare il testo della descrizione comando quando si è personalizzati disegnando la descrizione comando. È possibile utilizzare il Graphics.DrawString metodo per personalizzare il disegno del testo della descrizione comando. Se si desidera che il testo della descrizione comando venga disegnato usando lo stile specificato dal sistema, utilizzare il DrawText metodo . Il valore di testo proviene dal valore passato al SetToolTip metodo della ToolTip classe .

Si applica a

Vedi anche