DrawToolTipEventArgs.ToolTipText Eigenschap

Definitie

Hiermee haalt u de tekst op voor de ToolTip tekenreeks.

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

Waarde van eigenschap

De tekst die is gekoppeld aan de ToolTip gebeurtenis wanneer de Draw gebeurtenis plaatsvindt.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe u de ToolTipaangepaste tekening kunt maken. In het voorbeeld wordt er een ToolTip gemaakt en gekoppeld aan drie Button besturingselementen op de Form. In het voorbeeld wordt de OwnerDraw eigenschap ingesteld op true en wordt de Draw gebeurtenis verwerkt. In de Draw gebeurtenis-handler wordt de ToolTip aangepaste teken anders getekend, afhankelijk van de knop waarvoor de ToolTip knop wordt weergegeven, zoals aangegeven door de DrawToolTipEventArgs.AssociatedControl eigenschap.

In het onderstaande codefragment ziet u hoe u de DrawBorder methode gebruikt en de Boundseigenschappen ToolTipTexten Graphics eigenschappen gebruikt. Zie het DrawToolTipEventArgs klasseoverzicht voor het volledige codevoorbeeld.

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

Opmerkingen

Normaal gesproken gebruikt u de ToolTipText eigenschap om te bepalen wat de knopinfotekst is wanneer u aangepaste tekent. U kunt de Graphics.DrawString methode gebruiken om de tekening van de knopinfotekst aan te passen. Als u de knopinfotekst wilt laten tekenen met behulp van de door het systeem opgegeven stijl, gebruikt u de DrawText methode. De tekstwaarde is afkomstig van de waarde die wordt doorgegeven aan de SetToolTip methode van de ToolTip klasse.

Van toepassing op

Zie ook