DrawToolTipEventArgs.ToolTipText Propiedad

Definición

Obtiene el texto para el ToolTip que se ha dibujado.

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

Valor de propiedad

Texto asociado a ToolTip cuando se produce el evento Draw.

Ejemplos

En el ejemplo de código siguiente se muestra cómo dibujar de forma personalizada .ToolTip En el ejemplo se crea un ToolTip objeto y se asocia a tres Button controles ubicados en .Form En el ejemplo se establece la OwnerDraw propiedad en true y se controla el Draw evento. En el Draw controlador de eventos, ToolTip el elemento se dibuja de forma diferente en función del botón para el que se muestra el ToolTip valor indicado por la DrawToolTipEventArgs.AssociatedControl propiedad .

El fragmento de código siguiente muestra el uso del DrawBorder método y el uso de las Boundspropiedades , ToolTipTexty Graphics . Consulte la información general de la DrawToolTipEventArgs clase para obtener el ejemplo de código 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

Comentarios

Normalmente, usaría la ToolTipText propiedad para determinar qué es el texto de la información sobre herramientas cuando se crea un dibujo personalizado de la información sobre herramientas. Puede usar el Graphics.DrawString método para personalizar el dibujo del texto de información sobre herramientas. Si desea que el texto de información sobre herramientas se dibuje con el estilo especificado por el sistema, use el DrawText método . El valor de texto procede del valor pasado al SetToolTip método de la ToolTip clase .

Se aplica a

Consulte también