Sdílet prostřednictvím


DrawToolTipEventArgs.Graphics Vlastnost

Definice

Získá grafický povrch použitý k kreslení ToolTip.

public:
 property System::Drawing::Graphics ^ Graphics { System::Drawing::Graphics ^ get(); };
public System.Drawing.Graphics Graphics { get; }
member this.Graphics : System.Drawing.Graphics
Public ReadOnly Property Graphics As Graphics

Hodnota vlastnosti

Nakreslit GraphicsToolTip.

Příklady

Následující příklad kódu ukazuje, jak vlastní kreslení ToolTip. Příklad vytvoří ToolTip a přidruží ho ke třem Button ovládacím prvkům umístěným v souboru Form. Příklad nastaví OwnerDraw vlastnost na true a zpracuje Draw událost. V obslužné rutině Draw události je vlastní nakreslený odlišně v závislosti na tom, ToolTip jaké tlačítko ToolTip se zobrazuje podle vlastnosti DrawToolTipEventArgs.AssociatedControl .

Následující výňatek kódu ukazuje použití DrawText a DrawBackground metody a použití Graphics vlastnosti. Kompletní příklad kódu najdete v přehledu DrawToolTipEventArgs třídy.

// Draw a custom 3D border if the ToolTip is for button1.
if ( e->AssociatedControl == button1 )
{
   // Draw the standard background.
   e->DrawBackground();
   
   // Draw the custom border to appear 3-dimensional.
   array<Point>^ temp1 = {Point(0,e->Bounds.Height - 1),Point(0,0),Point(e->Bounds.Width - 1,0)};
   e->Graphics->DrawLines( SystemPens::ControlLightLight, temp1 );
   array<Point>^ temp2 = {Point(0,e->Bounds.Height - 1),Point(e->Bounds.Width - 1,e->Bounds.Height - 1),Point(e->Bounds.Width - 1,0)};
   e->Graphics->DrawLines( SystemPens::ControlDarkDark, temp2 );
   
   // Specify custom text formatting flags.
   TextFormatFlags sf = static_cast<TextFormatFlags>(TextFormatFlags::VerticalCenter | TextFormatFlags::HorizontalCenter | TextFormatFlags::NoFullWidthCharacterBreak);
   
   // Draw the standard text with customized formatting options.
   e->DrawText( sf );
}
// Draw a custom 3D border if the ToolTip is for button1.
if (e.AssociatedControl == button1)
{
    // Draw the standard background.
    e.DrawBackground();

    // Draw the custom border to appear 3-dimensional.
    e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
        new Point (0, e.Bounds.Height - 1), 
        new Point (0, 0), 
        new Point (e.Bounds.Width - 1, 0)
    });
    e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
        new Point (0, e.Bounds.Height - 1), 
        new Point (e.Bounds.Width - 1, e.Bounds.Height - 1), 
        new Point (e.Bounds.Width - 1, 0)
    });

    // Specify custom text formatting flags.
    TextFormatFlags sf = TextFormatFlags.VerticalCenter |
                         TextFormatFlags.HorizontalCenter |
                         TextFormatFlags.NoFullWidthCharacterBreak;

    // Draw the standard text with customized formatting options.
    e.DrawText(sf);
}
' Draw a custom 3D border if the ToolTip is for button1.
If (e.AssociatedControl Is button1) Then
    ' Draw the standard background.
    e.DrawBackground()

    ' Draw the custom border to appear 3-dimensional.
    e.Graphics.DrawLines( _
        SystemPens.ControlLightLight, New Point() { _
        New Point(0, e.Bounds.Height - 1), _
        New Point(0, 0), _
        New Point(e.Bounds.Width - 1, 0)})
    e.Graphics.DrawLines( _
        SystemPens.ControlDarkDark, New Point() { _
        New Point(0, e.Bounds.Height - 1), _
        New Point(e.Bounds.Width - 1, e.Bounds.Height - 1), _
        New Point(e.Bounds.Width - 1, 0)})

    ' Specify custom text formatting flags.
    Dim sf As TextFormatFlags = TextFormatFlags.VerticalCenter Or _
                         TextFormatFlags.HorizontalCenter Or _
                         TextFormatFlags.NoFullWidthCharacterBreak

    ' Draw standard text with customized formatting options.
    e.DrawText(sf)

Poznámky

Objekt slouží Graphics k přizpůsobení výkresu určitých vizuálních aspektů objektu ToolTip. Pomocí metody můžete například nakreslit vlastní pozadí Graphics.FillRectangle popisu.

Všechny vlastní výkresy provedené mimo obdélník určený Bounds vlastností se nezobrazí. Hranice před zobrazením můžete zvýšit ToolTip zpracováním ToolTip.Popup události.

Třída DrawToolTipEventArgs také poskytuje DrawBackgroundDrawText a DrawBorder metody kreslení jednotlivých částí ToolTip standardním způsobem používaným operačním systémem. Tyto metody můžete společně s objektovými Graphics metodami použít k vytvoření některých částí standardního popisu tooltipu a přizpůsobení dalších částí.

Platí pro