DrawToolTipEventArgs.Graphics Vlastnost

Definice

Získá grafickou plochu použitou k vykreslení objektu 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

Pole , Graphics na které se má nakreslit ToolTip.

Příklady

Následující příklad kódu ukazuje, jak vlastní nakreslit ToolTip. Příklad vytvoří a přidruží ToolTip ho ke třem Button ovládacím prvkům umístěným v 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 pro jaké tlačítko ToolTip se zobrazuje, jak označuje DrawToolTipEventArgs.AssociatedControl vlastnost .

Níže uvedený výňatek kódu ukazuje použití DrawText metod a DrawBackground a použití Graphics vlastnosti . Kompletní příklad kódu najdete v DrawToolTipEventArgs přehledu 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.

Vlastní výkres, který se provádí mimo obdélník určený Bounds vlastností, se nezobrazí. Zpracováním události můžete zvýšit hranice ToolTip před zobrazením ToolTip.Popup .

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

Platí pro