DrawToolTipEventArgs.Graphics Egenskap
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hämtar grafikytan som används för att rita 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
Egenskapsvärde
På Graphics vilken du ska rita ToolTip.
Exempel
I följande kodexempel visas hur du ritar ToolTip. Exemplet skapar en ToolTip och associerar den till tre Button kontroller som finns på Form. Exemplet anger OwnerDraw egenskapen till true och hanterar händelsen Draw . Draw I händelsehanteraren ToolTip är anpassade ritas olika beroende på vilken knapp ToolTip som visas för som anges av egenskapenDrawToolTipEventArgs.AssociatedControl.
Kodutdraget nedan visar hur du använder DrawText - och DrawBackground -metoderna och använder Graphics egenskapen . Se klassöversikten DrawToolTipEventArgs för det fullständiga kodexemplet.
// 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)
Kommentarer
Du använder Graphics objektet för att anpassa ritningen av vissa visuella aspekter av en ToolTip. Du kan till exempel rita en egen knappbeskrivningsbakgrund med hjälp Graphics.FillRectangle av metoden .
En anpassad ritning som görs utanför den rektangel som anges av Bounds egenskapen visas inte. Du kan öka gränserna ToolTip för innan det visas genom att hantera händelsen ToolTip.Popup .
Klassen DrawToolTipEventArgs innehåller DrawBackgroundockså metoderna , DrawText och DrawBorder för att rita enskilda delar av ToolTip på det standard sätt som används av operativsystemet. Du kan använda dessa metoder tillsammans med objektmetoderna Graphics för att göra vissa delar av din ToolTip-standard samtidigt som du anpassar andra delar.