2

Application is in c#/WinForm I'm using ToolStrip with button.

I setted ToolTipText, it is working.

Can I change the delay time to longer value ?

In other controls I'm using ToolTip control and it is possible (AutoPopDelay value).

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398

3 Answers3

2

In my other answer, I've showed how you can modify the initial delay, but as pointed out by Elmue in the comments, it looks like OP is looking for AutoPopDelay which is the duration of showing the tooltip.

To do so, you can get the internal ToolTip of ToolStrip and set its properties:

private void Form1_Load(object sender, EventArgs e)
{
    var toolTip = (ToolTip)this.toolStrip1.GetType()
        .GetProperty("ToolTip",
        System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance).GetValue(toolStrip1);
    toolTip.AutoPopDelay = 10000;
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • 1
    This should be the accepted answer. Just a note about the AutoPop delay. Default is 5 seconds which is extremely short. Windows limits this delay internally to 0x7FFF milliseconds. Any higher value will be ignored. So do not use more than 30000 ms. – Elmue Jun 10 '23 at 15:12
1

It's possible, but not as straightforward as you would expect.

The ToolStrip control doesn't expose a ToolTip property while it has an internal ToolTip property. In addition, the control doesn't rely on the automatic tooltip behavior and manually shows the tooltip on a Hover event. And the problem here, is hover event is also has a custom implementation relying on an internal timer.

Considering above facts, you can imagine how hacky is the solution to change the tooltip delay for toolstrip, and you decide whether it's worth it or not, but here is the solution:

private void TestForm_Load(object sender, EventArgs e)
{
    var mouseHoverTimerProperty =
        toolStrip1.GetType().GetProperty("MouseHoverTimer",
        BindingFlags.NonPublic | BindingFlags.Instance)
        .GetValue(toolStrip1);
    var mouseHoverTimerField =(System.Windows.Forms.Timer)
        (mouseHoverTimerProperty.GetType().GetFields(
        BindingFlags.NonPublic | BindingFlags.Instance)
        .Where(x => x.FieldType == typeof(System.Windows.Forms.Timer)).First()
        .GetValue(mouseHoverTimerProperty));

    mouseHoverTimerField.Interval = 3000;
}

Note: The reason that you see I've found the private field using its type but not its name, is because the name of the field in ".NET Framework" implementation is "mouseHoverTimer", and in the ".NET (CORE/5/6)" is "_mouseHoverTimer". That's is the problem when we rely on internal implementation details, but sometimes it's inevitable.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • This timer is by default 400 ms and defines the delay BEFORE the tooltip appears. But the question is about the AutoPop delay which is a completely different thing. The AutoPop delay defines how long the tooltip stays on the screen before it disappears alone. – Elmue Jun 08 '23 at 02:17
  • @Elmue Thanks, I added another answer showing how you can set AutoPopDelay for the ToolTip of toolstrip. It's relying on the reflection like this answer. – Reza Aghaei Jun 08 '23 at 17:30
  • I'll keep the other posts here as well as they show how to set initial delay which is much more tricky. – Reza Aghaei Jun 08 '23 at 17:31
  • I cannot see any sense in increasing the delay until the tooltip appears. If you set 3000 ms as in your example the user will think that the toolstrip has no tooltip! Which user will wait 3 seconds for a tooltip to appear? I find this code useless. A tooltip should appear as fast as possible otherwise you will bother the users of you software. – Elmue Jun 10 '23 at 15:18
  • The interval is set to 3000 for test purpose; to make the delay quite visible for the OP to test; you can set it to any value that you feel makes more sense as UX. – Reza Aghaei Jun 10 '23 at 17:30
  • And what value except the default of 400 ms makes sense to you ? – Elmue Jun 12 '23 at 21:42
0

Here's a totally different approach that you should almost always avoid, unless you know you are changing a system-wide setting which doesn't affect just your application.

As I mentioned in the other answer, there's an internal timer responsible for the hover time to shows the tooltip and the default interval for the timer is the value of SystemInformation.MouseHoverTime.

You can change the value using SystemParametersInfo. This value is a system-wide setting, and if you change it, it will be applied to all applications which rely on this value. That said, you decide whether you want to change it or not, but here is the solution:

Assuming you create the following helper class:

using System.Runtime.InteropServices;
public static class SystemInformationExtensions
{
    private const int SPI_SETMOUSEHOVERTIME = 0x0067;

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern bool SystemParametersInfo(
        int nAction, int nParam, ref int value, int ignore);
    public static void SetMouseHoverTime(int milliseconds)
    {
        SystemParametersInfo(SPI_SETMOUSEHOVERTIME,
            milliseconds, ref milliseconds,0);
    }
}

Then you can use it like this:

private void TestForm_Load(object sender, EventArgs e)
{
    SystemInformationExtensions.SetMouseHoverTime(3000);
}
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • This timer is by default 400 ms and defines the delay BEFORE the tooltip appears. But the question is about the AutoPop delay which is a completely different thing. The AutoPop delay defines how long the tooltip stays on the screen before it disappears alone. – Elmue Jun 08 '23 at 02:16