我可以在.NET Windows窗体窗口中为工具提示设置无限的AutoPopDelay吗?

时间:2022-11-28 09:35:37

I have a requirement to not have the standard .NET Windows Forms tooltip automatcially hide - that is, I need them to remain visible until the mouse moves off the control that has the tooltip. I'd like to avoid having to use specific MouseEnter and MouseLeave events for all controls with a tooltip. I'm happy to hear about third-party solutions if they'd solve the problem.

我要求不要自动隐藏标准的.NET Windows Forms工具提示 - 也就是说,我需要它们保持可见,直到鼠标移出具有工具提示的控件。我想避免使用工具提示对所有控件使用特定的MouseEnter和MouseLeave事件。如果他们能够解决问题,我很高兴听到第三方解决方案。

10 个解决方案

#1


As it has been posted countless times and is known from the .NET Framework early days, you cannot set the AutoPopDelay time higher than an Int16.MaxValue (i.e. 32767) and have it working. Using the tooltip Show() method leads to the same result. Any value higher than 32767 leads the timer to be reset to 5000 ms.

由于它已经无数次发布并且早期从.NET Framework中已知,因此您无法将AutoPopDelay时间设置为高于Int16.MaxValue(即32767)并使其正常工作。使用工具提示Show()方法会得到相同的结果。任何高于32767的值都会使定时器复位为5000 ms。

Even an attempt to set the AutomaticDelay to a value that leads to an AutoPopDelay value higher than 32767 will cause the tooltip not to work. Furthermore, using the StopTimer() method doesn't yield any positive results.

即使尝试将AutomaticDelay设置为导致AutoPopDelay值高于32767的值,也会导致工具提示无法工作。此外,使用StopTimer()方法不会产生任何积极的结果。

The only way I was succesful in displaying a tooltip with infinite timeout was using the tooltip Show() method that passes the displayed position. tooltip.Show(text, control, position). In conclusion, the tooltip control has the most bizarre behavior I have yet encountered in a control and the documentation about setting the delay times is quite misleading.

我在显示具有无限超时的工具提示时成功的唯一方法是使用工具提示Show()方法传递显示的位置。 tooltip.Show(文本,控件,位置)。总之,工具提示控件具有我在控件中遇到的最离奇的行为,并且关于设置延迟时间的文档非常容易引起误解。

#2


I was searching for a solution to the problem

我正在寻找解决问题的方法

  1. The popup baloon disappears too fast, not allowing me to read its content
  2. 弹出气球消失得太快,不允许我阅读其内容

  3. The popup baloon does not appear again when hovering into that region.
  4. 当徘徊在该区域时,弹出气球不再出现。

I found in the forums the following answer, which does not solve Problem2, but lets me read the text for more than the time I need when I set its value to 32766 and is thus - in my opinion - a kind of 'work around':

我在论坛中找到了以下答案,它没有解决问题2,但是当我将其值设置为32766时,让我阅读文本的时间超过了我需要的时间,因此 - 在我看来 - 是一种“解决问题” :

Actually, I found out my problem was that I assigned a value higher than 32767 (32768 and higher will have an effect of 5 sec) really weird, since AutoPopDelay is supposed to take an Integer (32 bit) as parameter, and 32767 is really a signed 16 bit ...

实际上,我发现我的问题是我分配的值高于32767(32768及更高版本的效果为5秒)真的很奇怪,因为AutoPopDelay应该以整数(32位)作为参数,而32767确实是签名16位......

But I have to admit, it still sucks...

但我必须承认,它仍然很糟糕......

But setting it to 32000 (32 seconds) seems to work better. No clue why this is but maybe it helps someone.

但将其设置为32000(32秒)似乎效果更好。不知道为什么这是,但也许它可以帮助某人。

#3


In my application, the tooltip text has to update every 10 seconds. What works for me is to deactivate and activate the tooltip every time this text is updated. When I set the AutoPopDelay to more than 10 seconds, the tooltip will effectively stay forever. So you might use a timer to repeatedly activate and deactivate the tooltip:

在我的应用程序中,工具提示文本必须每10秒更新一次。对我来说有用的是每次更新此文本时停用并激活工具提示。当我将AutoPopDelay设置为超过10秒时,工具提示将有效地保持不变。因此,您可以使用计时器重复激活和停用工具提示:

private void timer1_Tick(object sender, EventArgs e)
{
    toolTip1.Active = false;
    toolTip1.Active = true;
}

To minimize the flicker that happens on reactivating the tooltip, set the InitialDelay to 1. When you set the AutoPopDelay to 30000 and the timer interval also to 30000 you'll see a very short flicker only once every 30 seconds. For my application this short flicker is acceptable. Btw, don't forget to turn on the timer! (At first I thought it didn't work, until I discovered I forgot to turn on the timer ;-))

要最小化重新激活工具提示时发生的闪烁,请将InitialDelay设置为1.当您将AutoPopDelay设置为30000并且计时器间隔也设置为30000时,您将每30秒仅看到一次非常短的闪烁。对于我的应用,这种短暂的闪烁是可以接受的。顺便说一句,别忘了打开计时器! (起初我以为它不起作用,直到我发现我忘了打开计时器;-))

Of course this is a cure for the symptoms and not an elegant solution to the problem.

当然,这是治疗症状的方法,而不是解决问题的优雅方法。

#4


Try myToolTip.ReshowDelay = 0.

试试myToolTip.ReshowDelay = 0。

You just reshow the tooltip immediately after its delay expires. It worked for me.

您只需在延迟到期后立即重新显示工具提示。它对我有用。

#5


This is not going to be the answer you want to hear... Roll your own. I once had scenario where I wanted to simulate the new Office's ribbonbar tooltip behavour for shortcut keyboard commands and I found that the standard tooltip API is just too limited.

这不是你想听到的答案......滚动你自己。我曾经有过想要为快捷键盘命令模拟新Office的Ribbonbar工具提示行为的场景,我发现标准的工具提示API太有限了。

Make a small, simple and border-less form instance for every control that you need a tooltip for. Then show and hide them non-modally as you do a mouse-enter or -leave event. Have the constructor for this window receive the UI control instance and let it query the control for it's events so that it can attach itself to the mouse-enter and -leave events, so that you wouldn't have to wire them up manually.

为您需要工具提示的每个控件创建一个小而简单且无边框的表单实例。然后在执行鼠标输入或-leave事件时以非模态方式显示和隐藏它们。让这个窗口的构造函数接收UI控件实例,并让它查询控件的事件,以便它可以将自身附加到mouse-enter和-leave事件,这样你就不必手动连接它们。

#6


In my limited experience, I have found that setting the showAlways property to true has the side effect of making the tip display "infinitely" (until the cursor exits the control). This is not what the documentation says it will do, but that's what I have experienced. (However, I am using the Janus Supertip component, and it's possible that affects the behavior).

在我有限的经验中,我发现将showAlways属性设置为true具有使尖端显示为“无限”的副作用(直到光标退出控件)。这不是文档所说的,但这就是我所经历的。 (但是,我使用的是Janus Supertip组件,它可能会影响行为)。

#7


I think you are trying to cure the symptoms and not the cause of your problem.

我认为你正试图治愈症状,而不是你的问题的原因。

You are trying to force a ToolTip to be something different from a ToolTip. A tooltip is, by definition, "a small "hover box" with information about the item being hovered over".

您试图强制ToolTip与ToolTip不同。根据定义,工具提示是“一个小的”悬停框“,其中包含有关物品悬停的信息”。

If the user can't read what the tooltip is trying to suggest in 30 seconds, then it isn't really a "tip" but an entire chapter from the help file. Put lengthy instructions into the Manual and do not attempt to force it into a ToolTip that stays open forever.

如果用户无法在30秒内读取工具提示尝试建议的内容,那么它实际上不是“提示”,而是帮助文件中的整个章节。将冗长的指令放入手册中,不要试图将其强制插入永久保持打开的工具提示。

#8


So, I ended up de-activating the tooltip, but I am still using it to hold the text for the tooltip, because it neatly adds itself to all the controls. I made my own panel and label inside it for the tooltip and dynamically positioned, made visible and populated the text on the mouse enter and mouse leave events of all the controls.

所以,我最终取消激活工具提示,但我仍然使用它来保存工具提示的文本,因为它巧妙地将自己添加到所有控件中。我在其中制作了自己的面板和标签,用于工具提示并动态定位,使其可见并填充鼠标输入和鼠标离开所有控件的事件。

I also wrote a recursive function to add the mouse events to each label control (the only ones I have tooltips on), so I didn't have to manually to it and won't have to remember to do it when I add a new label. New developers on the project may not ever realise that the tooltip control is not actually rendering the tips.

我还写了一个递归函数来将鼠标事件添加到每个标签控件(我只有工具提示的那些),所以我没有手动操作它,并且在添加新的时不必记住这样做标签。该项目的新开发人员可能从未意识到工具提示控件实际上并未呈现提示。

Why a label in a panel? - so really big tooltips can scroll - although this is still not working nicely.

为什么面板上有标签? - 所以真正的大工具提示可以滚动 - 虽然这仍然不能很好地工作。

It is not real pretty, and I am still looking for a good answer if you've got on (or a critique of the method I've employed).

这不是真的很漂亮,如果你已经开始(或者对我采用的方法的批评),我仍然在寻找一个好的答案。

I came across http://www.binarymission.co.uk/, but their tooltip did not seem to render properly in my .NET 3.5 application. I am still talking to them.

我遇到了http://www.binarymission.co.uk/,但他们的工具提示似乎没有在我的.NET 3.5应用程序中正确呈现。我还在和他们说话。

#9


The ToolTip.StopTimer method might help. From MSDN:

ToolTip.StopTimer方法可能会有所帮助。来自MSDN:

The ToolTip class has an internal timer that it uses to set the display duration for ToolTips. The duration associated with this timer is set through the AutoPopDelay property. The StopTimer method will stop this internal timer, causing any displayed ToolTip to be shown modally until the Hide method is called, or the parent form is minimized, hidden, or closed.

ToolTip类有一个内部计时器,用于设置ToolTips的显示持续时间。与此计时器关联的持续时间是通过AutoPopDelay属性设置的。 StopTimer方法将停止此内部计时器,导致任何显示的工具提示以模态方式显示,直到调用Hide方法,或最小化,隐藏或关闭父窗体。

#10


Set the ToolTipService.ShowDuration attached property to int.MaxValue:

将ToolTipService.ShowDuration附加属性设置为int.MaxValue:

<Button 
  Height="23" Width="75"
  Content="Click Me" 
  ToolTip="My ToolTip" ToolTipService.ShowDuration="2147483647" 
/>

#1


As it has been posted countless times and is known from the .NET Framework early days, you cannot set the AutoPopDelay time higher than an Int16.MaxValue (i.e. 32767) and have it working. Using the tooltip Show() method leads to the same result. Any value higher than 32767 leads the timer to be reset to 5000 ms.

由于它已经无数次发布并且早期从.NET Framework中已知,因此您无法将AutoPopDelay时间设置为高于Int16.MaxValue(即32767)并使其正常工作。使用工具提示Show()方法会得到相同的结果。任何高于32767的值都会使定时器复位为5000 ms。

Even an attempt to set the AutomaticDelay to a value that leads to an AutoPopDelay value higher than 32767 will cause the tooltip not to work. Furthermore, using the StopTimer() method doesn't yield any positive results.

即使尝试将AutomaticDelay设置为导致AutoPopDelay值高于32767的值,也会导致工具提示无法工作。此外,使用StopTimer()方法不会产生任何积极的结果。

The only way I was succesful in displaying a tooltip with infinite timeout was using the tooltip Show() method that passes the displayed position. tooltip.Show(text, control, position). In conclusion, the tooltip control has the most bizarre behavior I have yet encountered in a control and the documentation about setting the delay times is quite misleading.

我在显示具有无限超时的工具提示时成功的唯一方法是使用工具提示Show()方法传递显示的位置。 tooltip.Show(文本,控件,位置)。总之,工具提示控件具有我在控件中遇到的最离奇的行为,并且关于设置延迟时间的文档非常容易引起误解。

#2


I was searching for a solution to the problem

我正在寻找解决问题的方法

  1. The popup baloon disappears too fast, not allowing me to read its content
  2. 弹出气球消失得太快,不允许我阅读其内容

  3. The popup baloon does not appear again when hovering into that region.
  4. 当徘徊在该区域时,弹出气球不再出现。

I found in the forums the following answer, which does not solve Problem2, but lets me read the text for more than the time I need when I set its value to 32766 and is thus - in my opinion - a kind of 'work around':

我在论坛中找到了以下答案,它没有解决问题2,但是当我将其值设置为32766时,让我阅读文本的时间超过了我需要的时间,因此 - 在我看来 - 是一种“解决问题” :

Actually, I found out my problem was that I assigned a value higher than 32767 (32768 and higher will have an effect of 5 sec) really weird, since AutoPopDelay is supposed to take an Integer (32 bit) as parameter, and 32767 is really a signed 16 bit ...

实际上,我发现我的问题是我分配的值高于32767(32768及更高版本的效果为5秒)真的很奇怪,因为AutoPopDelay应该以整数(32位)作为参数,而32767确实是签名16位......

But I have to admit, it still sucks...

但我必须承认,它仍然很糟糕......

But setting it to 32000 (32 seconds) seems to work better. No clue why this is but maybe it helps someone.

但将其设置为32000(32秒)似乎效果更好。不知道为什么这是,但也许它可以帮助某人。

#3


In my application, the tooltip text has to update every 10 seconds. What works for me is to deactivate and activate the tooltip every time this text is updated. When I set the AutoPopDelay to more than 10 seconds, the tooltip will effectively stay forever. So you might use a timer to repeatedly activate and deactivate the tooltip:

在我的应用程序中,工具提示文本必须每10秒更新一次。对我来说有用的是每次更新此文本时停用并激活工具提示。当我将AutoPopDelay设置为超过10秒时,工具提示将有效地保持不变。因此,您可以使用计时器重复激活和停用工具提示:

private void timer1_Tick(object sender, EventArgs e)
{
    toolTip1.Active = false;
    toolTip1.Active = true;
}

To minimize the flicker that happens on reactivating the tooltip, set the InitialDelay to 1. When you set the AutoPopDelay to 30000 and the timer interval also to 30000 you'll see a very short flicker only once every 30 seconds. For my application this short flicker is acceptable. Btw, don't forget to turn on the timer! (At first I thought it didn't work, until I discovered I forgot to turn on the timer ;-))

要最小化重新激活工具提示时发生的闪烁,请将InitialDelay设置为1.当您将AutoPopDelay设置为30000并且计时器间隔也设置为30000时,您将每30秒仅看到一次非常短的闪烁。对于我的应用,这种短暂的闪烁是可以接受的。顺便说一句,别忘了打开计时器! (起初我以为它不起作用,直到我发现我忘了打开计时器;-))

Of course this is a cure for the symptoms and not an elegant solution to the problem.

当然,这是治疗症状的方法,而不是解决问题的优雅方法。

#4


Try myToolTip.ReshowDelay = 0.

试试myToolTip.ReshowDelay = 0。

You just reshow the tooltip immediately after its delay expires. It worked for me.

您只需在延迟到期后立即重新显示工具提示。它对我有用。

#5


This is not going to be the answer you want to hear... Roll your own. I once had scenario where I wanted to simulate the new Office's ribbonbar tooltip behavour for shortcut keyboard commands and I found that the standard tooltip API is just too limited.

这不是你想听到的答案......滚动你自己。我曾经有过想要为快捷键盘命令模拟新Office的Ribbonbar工具提示行为的场景,我发现标准的工具提示API太有限了。

Make a small, simple and border-less form instance for every control that you need a tooltip for. Then show and hide them non-modally as you do a mouse-enter or -leave event. Have the constructor for this window receive the UI control instance and let it query the control for it's events so that it can attach itself to the mouse-enter and -leave events, so that you wouldn't have to wire them up manually.

为您需要工具提示的每个控件创建一个小而简单且无边框的表单实例。然后在执行鼠标输入或-leave事件时以非模态方式显示和隐藏它们。让这个窗口的构造函数接收UI控件实例,并让它查询控件的事件,以便它可以将自身附加到mouse-enter和-leave事件,这样你就不必手动连接它们。

#6


In my limited experience, I have found that setting the showAlways property to true has the side effect of making the tip display "infinitely" (until the cursor exits the control). This is not what the documentation says it will do, but that's what I have experienced. (However, I am using the Janus Supertip component, and it's possible that affects the behavior).

在我有限的经验中,我发现将showAlways属性设置为true具有使尖端显示为“无限”的副作用(直到光标退出控件)。这不是文档所说的,但这就是我所经历的。 (但是,我使用的是Janus Supertip组件,它可能会影响行为)。

#7


I think you are trying to cure the symptoms and not the cause of your problem.

我认为你正试图治愈症状,而不是你的问题的原因。

You are trying to force a ToolTip to be something different from a ToolTip. A tooltip is, by definition, "a small "hover box" with information about the item being hovered over".

您试图强制ToolTip与ToolTip不同。根据定义,工具提示是“一个小的”悬停框“,其中包含有关物品悬停的信息”。

If the user can't read what the tooltip is trying to suggest in 30 seconds, then it isn't really a "tip" but an entire chapter from the help file. Put lengthy instructions into the Manual and do not attempt to force it into a ToolTip that stays open forever.

如果用户无法在30秒内读取工具提示尝试建议的内容,那么它实际上不是“提示”,而是帮助文件中的整个章节。将冗长的指令放入手册中,不要试图将其强制插入永久保持打开的工具提示。

#8


So, I ended up de-activating the tooltip, but I am still using it to hold the text for the tooltip, because it neatly adds itself to all the controls. I made my own panel and label inside it for the tooltip and dynamically positioned, made visible and populated the text on the mouse enter and mouse leave events of all the controls.

所以,我最终取消激活工具提示,但我仍然使用它来保存工具提示的文本,因为它巧妙地将自己添加到所有控件中。我在其中制作了自己的面板和标签,用于工具提示并动态定位,使其可见并填充鼠标输入和鼠标离开所有控件的事件。

I also wrote a recursive function to add the mouse events to each label control (the only ones I have tooltips on), so I didn't have to manually to it and won't have to remember to do it when I add a new label. New developers on the project may not ever realise that the tooltip control is not actually rendering the tips.

我还写了一个递归函数来将鼠标事件添加到每个标签控件(我只有工具提示的那些),所以我没有手动操作它,并且在添加新的时不必记住这样做标签。该项目的新开发人员可能从未意识到工具提示控件实际上并未呈现提示。

Why a label in a panel? - so really big tooltips can scroll - although this is still not working nicely.

为什么面板上有标签? - 所以真正的大工具提示可以滚动 - 虽然这仍然不能很好地工作。

It is not real pretty, and I am still looking for a good answer if you've got on (or a critique of the method I've employed).

这不是真的很漂亮,如果你已经开始(或者对我采用的方法的批评),我仍然在寻找一个好的答案。

I came across http://www.binarymission.co.uk/, but their tooltip did not seem to render properly in my .NET 3.5 application. I am still talking to them.

我遇到了http://www.binarymission.co.uk/,但他们的工具提示似乎没有在我的.NET 3.5应用程序中正确呈现。我还在和他们说话。

#9


The ToolTip.StopTimer method might help. From MSDN:

ToolTip.StopTimer方法可能会有所帮助。来自MSDN:

The ToolTip class has an internal timer that it uses to set the display duration for ToolTips. The duration associated with this timer is set through the AutoPopDelay property. The StopTimer method will stop this internal timer, causing any displayed ToolTip to be shown modally until the Hide method is called, or the parent form is minimized, hidden, or closed.

ToolTip类有一个内部计时器,用于设置ToolTips的显示持续时间。与此计时器关联的持续时间是通过AutoPopDelay属性设置的。 StopTimer方法将停止此内部计时器,导致任何显示的工具提示以模态方式显示,直到调用Hide方法,或最小化,隐藏或关闭父窗体。

#10


Set the ToolTipService.ShowDuration attached property to int.MaxValue:

将ToolTipService.ShowDuration附加属性设置为int.MaxValue:

<Button 
  Height="23" Width="75"
  Content="Click Me" 
  ToolTip="My ToolTip" ToolTipService.ShowDuration="2147483647" 
/>