DrawToolTipEventArgs.Graphics Proprietà

Definizione

Ottiene la superficie grafica utilizzata per creare l'oggetto 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

Valore della proprietà

Oggetto Graphics sul quale creare l'oggetto ToolTip.

Esempio

Nell'esempio di codice seguente viene illustrato come disegnare personalizzato .ToolTip Nell'esempio viene creato un oggetto ToolTip e lo associa a tre Button controlli che si trovano nell'oggetto Form. L'esempio imposta la proprietà su true e gestisce l'evento OwnerDrawDraw . Nel gestore eventi, l'oggetto ToolTipDraw viene disegnato in modo diverso a seconda del pulsante ToolTip visualizzato per come indicato dalla DrawToolTipEventArgs.AssociatedControl proprietà.

L'estratto del codice seguente illustra l'uso dei DrawText metodi e DrawBackground e l'uso della Graphics proprietà . Vedere la panoramica della classe per l'esempio DrawToolTipEventArgs di codice completo.

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

Commenti

Si usa l'oggetto per personalizzare il Graphics disegno di determinati aspetti visivi di un ToolTipoggetto . Ad esempio, è possibile disegnare uno sfondo della descrizione comando personalizzato usando il Graphics.FillRectangle metodo .

Qualsiasi disegno personalizzato eseguito all'esterno Bounds del rettangolo specificato dalla proprietà non verrà visualizzato. È possibile aumentare i limiti dell'oggetto ToolTip prima che venga visualizzato gestendo l'evento ToolTip.Popup .

La DrawToolTipEventArgs classe fornisce anche i DrawBackgroundDrawText metodi e DrawBorder per disegnare singole parti dell'oggetto ToolTip nel modo standard usato dal sistema operativo. È possibile usare questi metodi, insieme ai metodi dell'oggetto Graphics , per rendere alcune parti dello standard ToolTip, mentre si personalizzano altre parti.

Si applica a