DrawToolTipEventArgs.Bounds 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 rozmiar i lokalizację ToolTip obiektu do rysowania.
public:
property System::Drawing::Rectangle Bounds { System::Drawing::Rectangle get(); };
public System.Drawing.Rectangle Bounds { get; }
member this.Bounds : System.Drawing.Rectangle
Public ReadOnly Property Bounds As Rectangle
Wartość nieruchomości
Obiekt Rectangle reprezentujący granice ToolTip obiektu do rysowania.
Przykłady
Poniższy przykład kodu przedstawia sposób niestandardowego rysowania elementu ToolTip. W przykładzie tworzony jest obiekt ToolTip i kojarzy go z trzema Button kontrolkami znajdującymi się w obiekcie Form. W przykładzie OwnerDraw właściwość jest ustawiana na wartość true i obsługuje Draw zdarzenie. W procedurze obsługi zdarzeń Draw obiekt jest rysowany w inny sposób w zależności od tego, ToolTip dla którego przycisku ToolTip jest wyświetlany, zgodnie z właściwością DrawToolTipEventArgs.AssociatedControl .
Poniższy fragment kodu przedstawia użycie DrawBorder metody i właściwości Bounds, ToolTipTexti Graphics . Zobacz omówienie klasy, DrawToolTipEventArgs aby zapoznać się z 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
Domyślnie granice są ustawiane przez system operacyjny na podstawie ustawień systemu i ToolTip tekstu. Granice ToolTip klasy można zwiększyć, zanim będzie ona wyświetlana, obsługując PopupPopup zdarzenie ToolTip klasy.