DrawToolTipEventArgs.Bounds Eigenschaft

Definition

Ruft die Größe und die Position des zu zeichnenden ToolTip ab.Gets the size and location of the ToolTip to draw.

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

Eigenschaftswert

Ein Rectangle, das die Begrenzungen des zu zeichnenden ToolTip darstellt.A Rectangle that represents the bounds of the ToolTip to draw.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die ToolTipbenutzerdefinierte gezeichnet wird.The following code example demonstrates how to custom draw the ToolTip. Im Beispiel wird ein ToolTip erstellt und den drei Button Steuerelementen in Formzugeordnet.The example creates a ToolTip and associates it to three Button controls located on the Form. Im Beispiel wird die OwnerDraw -Eigenschaft auf true festgelegt Draw und das-Ereignis behandelt.The example sets the OwnerDraw property to true and handles the Draw event. Im- ToolTip ToolTip Ereignishandler wird der benutzerdefinierte gezeichnet, abhängig von der Schaltfläche, für die der angezeigt wird, wie DrawToolTipEventArgs.AssociatedControl von der-Eigenschaft angegeben. DrawIn the Draw event handler, the ToolTip is custom drawn differently depending on what button the ToolTip is being displayed for as indicated by the DrawToolTipEventArgs.AssociatedControl property.

Der folgende Code Ausschnitt veranschaulicht die Verwendung DrawBorder der-Methode und Boundsdie ToolTipTextVerwendung der Graphics Eigenschaften, und.The code excerpt below demonstrates using the DrawBorder method and using the Bounds, ToolTipText, and Graphics properties. Das gesamte DrawToolTipEventArgs Codebeispiel finden Sie in der Übersicht über die-Klasse.See the DrawToolTipEventArgs class overview for the complete code example.

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

Hinweise

Standardmäßig werden die Begrenzungen vom Betriebssystem basierend auf den Systemeinstellungen und dem ToolTip Text festgelegt.By default, the bounds are set by the operating system based on system settings and the ToolTip text. Sie können die Begrenzungen ToolTip des erhöhen, bevor es angezeigt wird, indem Sie das Popup Popup -Ereignis ToolTip der-Klasse behandeln.You can increase the bounds of the ToolTip before it is shown by handling the PopupPopup event of the ToolTip class.

Gilt für: