DrawToolTipEventArgs Class


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

Provides data for the ToolTip.Draw event.

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


public class DrawToolTipEventArgs : EventArgs


Gets the control for which the ToolTip is being drawn.


Gets the window to which this ToolTip is bound.


Gets the size and location of the ToolTip to draw.


Gets the font used to draw the ToolTip.


Gets the graphics surface used to draw the ToolTip.


Gets the text for the ToolTip that is being drawn.


Draws the background of the ToolTip using the system background color.


Draws the border of the ToolTip using the system border color.


Draws the text of the ToolTip using the system text color and font.


Draws the text of the ToolTip using the system text color and font, and the specified text layout.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

The ToolTip.Draw event is raised by the ToolTip class when the ToolTip is drawn and the ToolTip.OwnerDraw property value is true. The handler for this event receives a parameter of type DrawToolTipEventArgs. The DrawToolTipEventArgs class contains all the information needed to paint the ToolTip, including the ToolTip text, the Rectangle, and the Graphics object on which the drawing should be done. To customize the look of the ToolTip, use the Rectangle to determine the bounds of the ToolTip, and the Graphics object to perform your customized drawing. You can increase the bounds of the ToolTip before it is shown by handling the Popup event.

DrawToolTipEventArgs also supports partial customization through the DrawBackground, DrawText and DrawBorder methods. Using these methods, you can owner draw portions of the ToolTip while leaving the other portions drawn in the standard way.

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.

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace ToolTipExample
    // Form for the ToolTip example.
    public class ToolTipExampleForm : System.Windows.Forms.Form
        private System.Windows.Forms.ToolTip toolTip1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;

        public ToolTipExampleForm()
            // Create the ToolTip and set initial values.
            this.toolTip1 = new System.Windows.Forms.ToolTip();
            this.toolTip1.AutoPopDelay = 5000;
            this.toolTip1.InitialDelay = 500;
            this.toolTip1.OwnerDraw = true;
            this.toolTip1.ReshowDelay = 10;
            this.toolTip1.Draw += new DrawToolTipEventHandler(this.toolTip1_Draw);
            this.toolTip1.Popup += new PopupEventHandler(toolTip1_Popup);

            // Create button1 and set initial values.
            this.button1 = new System.Windows.Forms.Button();
            this.button1.Location = new System.Drawing.Point(8, 8);
            this.button1.Text = "Button 1";
            this.toolTip1.SetToolTip(this.button1, "Button1 tip text");

            // Create button2 and set initial values.
            this.button2 = new System.Windows.Forms.Button();
            this.button2.Location = new System.Drawing.Point(8, 32);
            this.button2.Text = "Button 2";
            this.toolTip1.SetToolTip(this.button2, "Button2 tip text");

            // Create button3 and set initial values.
            this.button3 = new System.Windows.Forms.Button();
            this.button3.Location = new System.Drawing.Point(8, 56);
            this.button3.Text = "Button 3";
            this.toolTip1.SetToolTip(this.button3, "Button3 tip text");

            // Set up the Form.
            this.Controls.AddRange(new Control[] {
                this.button1, this.button2, this.button3
            this.Text = "owner drawn ToolTip example";

        // Clean up any resources being used.        
        protected override void Dispose(bool disposing)
            if (disposing)


        // The main entry point for the application.
        static void Main()
            Application.Run(new ToolTipExampleForm());

        // Determines the correct size for the button2 ToolTip.
        private void toolTip1_Popup(object sender, PopupEventArgs e)
            if (e.AssociatedControl == button2)
                using (Font f = new Font("Tahoma", 9))
                    e.ToolTipSize = TextRenderer.MeasureText(
                        toolTip1.GetToolTip(e.AssociatedControl), f);

        // Handles drawing the ToolTip.
        private void toolTip1_Draw(System.Object sender, 
            System.Windows.Forms.DrawToolTipEventArgs e)
            // Draw the ToolTip differently depending on which 
            // control this ToolTip is for.
            // 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.
            // Draw a custom background and text if the ToolTip is for button2.
            else if (e.AssociatedControl == button2)
                // Draw the custom background.
                e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, e.Bounds);

                // Draw the standard border.

                // Draw the custom text.
                // The using block will dispose the StringFormat automatically.
                using (StringFormat sf = new StringFormat())
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;
                    sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
                    sf.FormatFlags = StringFormatFlags.NoWrap;
                    using (Font f = new Font("Tahoma", 9))
                        e.Graphics.DrawString(e.ToolTipText, f, 
                            SystemBrushes.ActiveCaptionText, e.Bounds, sf);
            // Draw the ToolTip using default values if the ToolTip is for button3.
            else if (e.AssociatedControl == button3)

.NET Framework
Available since 2.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top