Per Erik Strandberg /cv /kurser /blog

After messing a lot with tool tips and reading some blogs I think I've made a minimal example that illustrates how to customize the tool tip by just hooking into the ToolTip.Popup and ToolTip.Draw events.

    this.m_toolTip.Popup += new PopupEventHandler(toolTip1_Popup);
    this.m_toolTip.Draw += new DrawToolTipEventHandler(toolTip1_Draw);

While running it looks a little something like this:

One really important property is OwnerDraw that according to [1] the property Gets or sets a value indicating whether the ToolTip is drawn by the operating system or by code that you provide. So set it to true.

    this.m_toolTip.OwnerDraw = true;

The event handlers I wrote (copied from the web) resize the tool tip and draws something different than the tooltip, so the OwnerDraw property of the tool tip must be true.

        void toolTip1_Popup(object sender, PopupEventArgs e)
            SizeF size = e.AssociatedControl.CreateGraphics().MeasureString(
            e.ToolTipSize = new Size(

        void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
            DrawToolTipEventArgs newArgs = new DrawToolTipEventArgs(e.Graphics,
                e.AssociatedWindow, e.AssociatedControl, e.Bounds, e.ToolTipText,
                m_toolTip.BackColor, m_toolTip.ForeColor, m_font);


Download code here [2] and executable here: [3]

See also Csharp Tool Tip Test, Csharp Override Tool Tip Test and Csharp Data Grid View And Tool Tip Test.

Tillhör Kategori Programmering