DrawToolTipEventArgs.Graphics Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene la superficie grafica utilizzata per disegnare 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 in cui disegnare l'oggetto ToolTip.
Esempio
Nell'esempio di codice seguente viene illustrato come disegnare l'oggetto ToolTippersonalizzato. L'esempio crea un oggetto ToolTip e lo associa a tre Button controlli che si trovano nell'oggetto Form. Nell'esempio la OwnerDraw proprietà viene impostata su true e viene gestito l'evento Draw . Nel gestore eventi l'oggetto DrawToolTip viene disegnato in modo diverso a seconda del pulsante ToolTip per cui viene visualizzato come indicato dalla DrawToolTipEventArgs.AssociatedControl proprietà .
L'estratto di codice riportato di seguito illustra l'uso dei DrawText metodi e DrawBackground e l'uso della Graphics proprietà . Vedere la panoramica della DrawToolTipEventArgs classe per l'esempio 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
Utilizzare l'oggetto Graphics per personalizzare il disegno di determinati aspetti visivi di un oggetto ToolTip. Ad esempio, è possibile disegnare uno sfondo della descrizione comando personalizzato usando il Graphics.FillRectangle metodo .
Qualsiasi disegno personalizzato eseguito all'esterno del rettangolo specificato dalla Bounds proprietà non verrà visualizzato. È possibile aumentare i limiti di prima che ToolTip venga visualizzato gestendo l'evento ToolTip.Popup .
La DrawToolTipEventArgs classe fornisce anche i DrawBackgroundmetodi , DrawText e DrawBorder per disegnare singole parti di ToolTip nel modo standard usato dal sistema operativo. È possibile usare questi metodi, insieme Graphics ai metodi oggetto, per creare alcune parti dello standard ToolTip, personalizzando altre parti.