DrawToolTipEventArgs.ToolTipText Własność
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Pobiera tekst, który ToolTip jest rysowany.
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
Wartość nieruchomości
Tekst skojarzony z zdarzeniem ToolTipDraw .
Przykłady
Poniższy przykład kodu przedstawia sposób niestandardowego rysowania elementu ToolTip. Przykład tworzy obiekt ToolTip i kojarzy go z trzema Button kontrolkami znajdującymi się w obiekcie Form. Przykład ustawia OwnerDraw właściwość na wartość true i obsługuje Draw zdarzenie. W procedurze obsługi zdarzeń Draw obiekt jest rysowany inaczej w zależności od tego, ToolTip jaki przycisk ToolTip jest wyświetlany dla DrawToolTipEventArgs.AssociatedControl właściwości.
Poniższy fragment kodu przedstawia użycie DrawBorder metody i właściwości Bounds, ToolTipTexti Graphics . Zobacz omówienie klasy, aby zapoznać się z DrawToolTipEventArgs kompletnym przykładem kodu.
// 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
Uwagi
Zazwyczaj należy użyć ToolTipText właściwości , aby określić, jaki tekst etykietki narzędzia jest wyświetlany podczas niestandardowego rysowania etykietki narzędzia. Możesz użyć Graphics.DrawString metody , aby dostosować rysunek tekstu etykietki narzędzia. Jeśli chcesz, aby tekst etykietki narzędzia został narysowany przy użyciu określonego DrawText stylu systemu, użyj metody . Wartość tekstowa pochodzi z wartości przekazanej ToolTip do SetToolTip metody klasy.