none
Is there a way to have a Tooltip display for longer than 5 seconds?

    Question

  • It doesn't look like there's a good answer to the question, but I'd like to be able to assign tooltips to a set of controls on a form with the Tooltip class, but it doesn't look like there's any way to have them display for more than 5 seconds (since this is defined as the maximum in the docs).  Is there a way, short of writing your own tooltip class from scratch, to get a tooltip to display for longer than 5 seconds? 
    Thursday, August 14, 2008 3:03 PM

Answers

  • Thanks for the suggestion on that TTM_SETDELAYTIME message-I managed to get something working with a little searching, and some reflection (this article also helped:http://www.codeproject.com/KB/miscctrl/Balloon_ToolTip.aspx).  Here's a code snippet:

    Code Snippet

    private const int WM_USER = 0x0400;
    private const int TTM_SETDELAYTIME = (WM_USER + 3);
    private const int TTDT_AUTOPOP = 2;

    [DllImport("user32.dll", EntryPoint = "SendMessageA", SetLastError = true)]
    private static extern int SendMessageDelay(IntPtr hWnd, int message, int wParam, int lParam);

    private static void SetTipDelay(ToolTip tip,int delay)
    {
    FieldInfo windowField = tip.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
    NativeWindow window = (NativeWindow)windowField.GetValue(tip);
    if (window.Handle != IntPtr.Zero)
    {
    int rc = SendMessageDelay(window.Handle, TTM_SETDELAYTIME, TTDT_AUTOPOP, delay);
    }
    }


    Apparently the delay time maxes out at about 32s, but that's much better than the 5 seconds I was able to set before.  At least that's a partial solution-I wonder why .net has the arbitrary limit on it when win32 can obviously handle it? 
    Thursday, August 14, 2008 8:23 PM

All replies

  • Well, you don't have to rewrite the ToolTip class to do that. It already has the behavior you need:

     

    Code Snippet

       ToolTip toolTip1 = new ToolTip();

     
       toolTip1.AutoPopDelay = 5000;
       toolTip1.InitialDelay = 1000;
       toolTip1.ReshowDelay = 500;

     

     

    Also, see this: http://msdn.microsoft.com/en-us/library/system.windows.forms.tooltip.autopopdelay.aspx

     

    Regards,

    Thursday, August 14, 2008 3:17 PM
  • Yes, I know.  I already read that entry, and tried setting those properties.  As I said the AutoPopDelay maxes out at 5000 ms (as that link clearly states), so if I want my tooltip to display for, say, 30 seconds, that won't do me any good, will it?

    The overloads of Show() allow you to specify a delay, but these also have a maximum of 5000 ms, so the question still stands-how can you show a tooltip for longer than 5 seconds.  I
    Thursday, August 14, 2008 3:23 PM
  •  Chris Bardon wrote:
    (as that link clearly states),

    Oh, I paid no atention to this... Sorry.

     

    I've read a few things that might help you. Seems like you'll have to modify the TTM_SETDELAYTIME Message. As I've read here, it controls the timer for the ToolTip. Looking for a way to modify  TTM_SETDELAYTIME I came to this question in these forums. I see that the question is unanswered and that the poster didn't recieved the answer. But a poster in there linked to this thread: http://www.vbmonster.com/Uwe/Forum.aspx/basic/806/Multiline-tooltip-problem/. See if the code from this last link works.

    I'm sorry I can't do it myself, but I have no IDE installed on this computer. Tell us if it works.

     

    Regards,

     

     

    Thursday, August 14, 2008 3:54 PM
  •  

    Hi,Chris,

     

    u can try the method ToolTip.Show(String, IWin32Window, Int32) if ur application is based on .net framework2.0 or above.

    text

    A String containing the new ToolTip text.

    window

    The Control to display the ToolTip for.

    duration

    An Int32 containing the duration, in milliseconds, to display the ToolTip.

     

    Thursday, August 14, 2008 6:47 PM
  • And,if ur framewordk version is early than 2.0,u can try the property AutomaticDelay, plz refer to  http://msdn.microsoft.com/en-us/system.windows.forms.tooltip.automaticdelay(VS.80).aspx

     

    But in this case ,the InitialDelay value will equal to AutomaticDelay,it's too bad.

     

    Maybe the code could also be helpful to u,

     

    Code Snippet

    for(int i=0;i<=5;i++)
       {
        ToolTip toolTip1 = new ToolTip();
        toolTip1.AutoPopDelay = 5000;
        toolTip1.InitialDelay = 1000;
        toolTip1.ReshowDelay = 500;   
        toolTip1.SetToolTip(this.button1,"abc");
       }

     

     

    u can get a 25s duration,but don't set InitialDealy too samll.

     

    Good Luck!

    Thursday, August 14, 2008 7:00 PM
  • Kuki, I have no idea what you're expecting to do there-why would assigning a tooltip to a control five times change anything?  As I said earlier, since the autoPopDelay is limited by .net to a maximum of 5000 ms, there is no way to directly set a 30s delay. 
    Thursday, August 14, 2008 8:17 PM
  • Thanks for the suggestion on that TTM_SETDELAYTIME message-I managed to get something working with a little searching, and some reflection (this article also helped:http://www.codeproject.com/KB/miscctrl/Balloon_ToolTip.aspx).  Here's a code snippet:

    Code Snippet

    private const int WM_USER = 0x0400;
    private const int TTM_SETDELAYTIME = (WM_USER + 3);
    private const int TTDT_AUTOPOP = 2;

    [DllImport("user32.dll", EntryPoint = "SendMessageA", SetLastError = true)]
    private static extern int SendMessageDelay(IntPtr hWnd, int message, int wParam, int lParam);

    private static void SetTipDelay(ToolTip tip,int delay)
    {
    FieldInfo windowField = tip.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
    NativeWindow window = (NativeWindow)windowField.GetValue(tip);
    if (window.Handle != IntPtr.Zero)
    {
    int rc = SendMessageDelay(window.Handle, TTM_SETDELAYTIME, TTDT_AUTOPOP, delay);
    }
    }


    Apparently the delay time maxes out at about 32s, but that's much better than the 5 seconds I was able to set before.  At least that's a partial solution-I wonder why .net has the arbitrary limit on it when win32 can obviously handle it? 
    Thursday, August 14, 2008 8:23 PM
  • hi,chris,

     

    As I showed u before,if u assign a tooltip n times , u can get a n times display time of the tooltip.Just have a try,compile and run that code ,maybe something different with what u considered. It DO change something.

    Though there is a limitation of 5000ms,but 5000ms*6=30s,right?

     

    Actually,not ONE tooltip was assigned,   plz see about that "Tooltip tooptip1 = new Tooltip"  is in the loop body, that means n Tooltip instance was created and assigned.

     

    To be frankly ,it's not a good style of programming,except a little easier for ur coding.

     

     

    Friday, August 15, 2008 2:00 AM
  • Apparently the delay time maxes out at about 32s, but that's much better than the 5 seconds I was able to set before.  At least that's a partial solution-I wonder why .net has the arbitrary limit on it when win32 can obviously handle it? 
    Actually, Win32 Can't:

    http://blogs.msdn.com/oldnewthing/archive/2003/11/10/55635.aspx

    The ToolTip class is a Windows Forms wrapper around the Common Controls ToolTip window class . If you look at the documentation for the TTM_SETDELAYTIME message, you'll see that the delay time (iTime ) is passed in the low word of the lParam parameter. Consequently, it is limited to a 16-bit value, and in this case, it's a signed 16-bit value since negative values for iTime have special meaning (as noted in the documentation).

    Since the maximum value for a signed 16-bit integer is 32767, the maximum value you can set for the delay time is a little over 32 seconds.

    So if you try to set your ToolTip.AutoPopDelay to something longer, like 60 seconds, you will find that the delay time is not properly set, since the ToolTip class merely passes the delay value through to the underlying control. And until you understood the underlying control, you would never understand why.
    • Proposed as answer by yosi142 Saturday, October 01, 2011 5:56 PM
    Saturday, March 13, 2010 12:52 PM
  • I get my tool tips to stay up for 30 seconds by using the following properties settings: AutomaticDelay 30, AutoPopDelay 30000, InitialDelay 30, and ReshowDelay 100. 
    Wednesday, April 07, 2010 3:32 AM
  • I get my tool tips to stay up for 30 seconds by using the following properties settings on the tooltip control: AutomaticDelay 30, AutoPopDelay 30000, InitialDelay 30, and ReshowDelay 100. 
    Wednesday, April 07, 2010 3:32 AM
  • Hi all 

    Can I summarize that solution to be clear for others....

    toolTip.AutoPopDelay=5000;  // 5 secs is the default delay

    The underlying native code passes the delay value as a 16 bit value. 
    So 32767 (largest 16bit number) is the maximum ms delay you can set.
    If you go over this max word value you end up with the 5000ms default. 

    toolTip.AutoPopDelay=32767;   // This works - The max value (about 32seconds)

    toolTip.AutoPopDelay = Int16.MaxValue;  // Same thing - Works!

    toolTip.AutoPopDelay=32768;   // Does not work!! > You end up back at 5sec if you go over 32767

     

    Thanks guys your comments really helped.

     


    Rob Chandler Help MVP http://Helpware.net/ http://mshcmigrate.helpmvp.com/
    Saturday, October 01, 2011 5:53 PM