DrawToolTipEventArgs.Graphics Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the graphics surface used to draw the ToolTip.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Graphics Graphics { get; }

Property Value

Type: System.Drawing.Graphics

The Graphics on which to draw the ToolTip.

You use the Graphics object to customize the drawing of certain visual aspects of a ToolTip. For example, you can draw your own ToolTip background by using the Graphics.FillRectangle method.

Any custom drawing that is done outside of the rectangle specified by the Bounds property will not show up. You can increase the bounds of the ToolTip before it is shown by handling the ToolTip.Popup event.

The DrawToolTipEventArgs class also provides the DrawBackground, DrawText and DrawBorder methods to draw individual parts of the ToolTip in the standard way used by the operating system. You can use these methods, together with the Graphics object methods, to make some parts of your ToolTip standard, while customizing other parts.

The following code example demonstrates how to custom draw the ToolTip. The example creates a ToolTip and associates it to three Button controls located on the Form. The example sets the OwnerDraw property to true and handles the Draw event. In the Draw event handler, the ToolTip is custom drawn differently depending on what button the ToolTip is being displayed for as indicated by the DrawToolTipEventArgs.AssociatedControl property.

The code excerpt below demonstrates using the DrawText and DrawBackground methods and using the Graphics property. See the DrawToolTipEventArgs class overview for the complete code example.

// Draw a custom 3D border if the ToolTip is for button1.
if (e.AssociatedControl == button1)
    // Draw the standard background.

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

    // Draw the standard text with customized formatting options.

.NET Framework
Available since 2.0
Return to top