如何确定何时显示工具提示?

时间:2022-10-14 07:27:40

I'm writing a calendar control in .Net WinForms that will show a tooltip for each date.

我正在.Net WinForms中编写一个日历控件,它将显示每个日期的工具提示。

What's the best way to determine when to show the tooltip?

确定何时显示工具提示的最佳方法是什么?

Showing it immediately in MouseMove would make it get in the way, so I'd like it to show when the mouse hovers over each date cell.

在MouseMove中立即显示它会使它受阻,所以我希望它显示鼠标悬停在每个日期单元格上的时间。

The MouseHover event only fires on the first hover after MouseEnter, so I can't use it.

MouseHover事件仅在MouseEnter之后的第一个悬停时触发,因此我无法使用它。

What's the best way to do this?

最好的方法是什么?

EDIT:I'm using WinForms

编辑:我正在使用WinForms

3 个解决方案

#1


The time delay between Enter and Hover is specified in SystemInformation.MouseHoverTime.

Enter和Hover之间的时间延迟在SystemInformation.MouseHoverTime中指定。

If for some reason the built-in tooltip handling code for whichever UI framework you're using isn't sufficient, you could just spin up a Timer after each MouseMove and show a Tooltip when it fires. Obviously, you'd need to reset the Timer each time the mouse is moved to prevent a long series "rain of tooltips".

如果由于某种原因,您使用的任何UI框架的内置工具提示处理代码都不够,您可以在每个MouseMove之后启动一个Timer,并在它触发时显示工具提示。显然,每次移动鼠标时都需要重置Timer,以防止出现长串“工具提示雨”。

#2


It would be helpful to know which technology you are using (ASP.NET? Forms? WPF?) because they all have different ways of implementing tooltips:

了解您正在使用哪种技术(ASP.NET?Forms?WPF?)会有所帮助,因为它们都有不同的实现工具提示的方法:

  • With ASP.NET, you can simply set the ToolTip property of a control (such as a Label control that shows a number in your calendar), and it will automatically show a tooltip after a slight delay when hovering over the control.
  • 使用ASP.NET,您可以简单地设置控件的ToolTip属性(例如在日历中显示数字的Label控件),并且在将鼠标悬停在控件上时会稍微延迟后自动显示工具提示。

  • In Forms, I think you have to actually create a ToolTip object then attach a control to it.
  • 在Forms中,我认为您必须实际创建一个ToolTip对象,然后将控件附加到它。

  • In WPF, you can add a Label.ToolTip element to your XAML code.
  • 在WPF中,您可以将Label.ToolTip元素添加到XAML代码中。

In all cases, though, there's a built-in way to do it, so it might not be necessary for you to write your own code at all.

但是,在所有情况下,都有内置的方法来执行此操作,因此您可能根本不需要编写自己的代码。

If your situation is so custom that you do need to write your own code, I'd really need to know more about how you are representing the numbers in your calendar to help you out.

如果你的情况是如此自定义,你需要编写自己的代码,我真的需要了解更多关于你如何表示日历中的数字来帮助你。

Last thing: you didn't really ask this--and it may not be under your control--but you might want to ask yourself whether a tooltip is the best way to show calendar information in the first place. If space is really tight, then the answer might be "yes", but if you have enough space to show the calendar events (or even the first few words of each event), this would save the user from having to "scrub the whole calendar" (i.e., roll over each date individually).

最后一件事:你并没有真正问过这个 - 它可能不在你的控制之下 - 但是你可能想问问自己,工具提示是否是首先显示日历信息的最佳方式。如果空间非常紧张,那么答案可能是“是”,但是如果你有足够的空间来显示日历事件(甚至每个事件的前几个单词),这将使用户不​​必“擦洗整个日历“(即,单独滚动每个日期)。

-Dan

#3


Have a look at the AutoPopDelay, InitialDelay and ReshowDelay properties of the ToolTip class, as they control the behaviour of the tooltip.

查看ToolTip类的AutoPopDelay,InitialDelay和ReshowDelay属性,因为它们控制工具提示的行为。

I generally play around with the values until I get something that 'feels' right. It's annoying when a tooltip shows immediately, and for short tooltips, it's also annoying when they disappear too soon. For really long tooltips, say, several paragraphs (yes, poor design decision, but if there's a lot of info to read, at least let me read it!) then it should stay open as long as my mouse is stationary.

我通常会玩弄价值观,直到我得到“感觉”正确的东西。当工具提示立即显示时很烦人,而对于简短的工具提示,当它们过早消失时它也很烦人。对于很长的工具提示,比如几个段落(是的,糟糕的设计决定,但如果有很多信息需要阅读,至少让我读一读!)那么只要我的鼠标静止就应该保持打开状态。

A tooltip example from MSDN gives the following values:

MSDN中的工具提示示例提供以下值:

 AutoPopDelay = 5000;
 InitialDelay = 1000;
 ReshowDelay = 500;
 // Force the ToolTip text to be displayed whether or not the form is active.
 ShowAlways = true;

As mentioned in a comment, the poster wants to trigger the tooltip programatically. For that, ToolTip.Show( ) needs to be called. To get a delay effect, you'll likely want to have a timer running which counts the time that the mouse is stationary. Whenever the mouse enters, leaves or moves within the control, this time should be reset.

正如评论中所提到的,海报希望以编程方式触发工具提示。为此,需要调用ToolTip.Show()。要获得延迟效果,您可能希望运行一个计时器来计算鼠标静止的时间。只要鼠标在控件内进入,离开或移动,就应该重置此时间。

#1


The time delay between Enter and Hover is specified in SystemInformation.MouseHoverTime.

Enter和Hover之间的时间延迟在SystemInformation.MouseHoverTime中指定。

If for some reason the built-in tooltip handling code for whichever UI framework you're using isn't sufficient, you could just spin up a Timer after each MouseMove and show a Tooltip when it fires. Obviously, you'd need to reset the Timer each time the mouse is moved to prevent a long series "rain of tooltips".

如果由于某种原因,您使用的任何UI框架的内置工具提示处理代码都不够,您可以在每个MouseMove之后启动一个Timer,并在它触发时显示工具提示。显然,每次移动鼠标时都需要重置Timer,以防止出现长串“工具提示雨”。

#2


It would be helpful to know which technology you are using (ASP.NET? Forms? WPF?) because they all have different ways of implementing tooltips:

了解您正在使用哪种技术(ASP.NET?Forms?WPF?)会有所帮助,因为它们都有不同的实现工具提示的方法:

  • With ASP.NET, you can simply set the ToolTip property of a control (such as a Label control that shows a number in your calendar), and it will automatically show a tooltip after a slight delay when hovering over the control.
  • 使用ASP.NET,您可以简单地设置控件的ToolTip属性(例如在日历中显示数字的Label控件),并且在将鼠标悬停在控件上时会稍微延迟后自动显示工具提示。

  • In Forms, I think you have to actually create a ToolTip object then attach a control to it.
  • 在Forms中,我认为您必须实际创建一个ToolTip对象,然后将控件附加到它。

  • In WPF, you can add a Label.ToolTip element to your XAML code.
  • 在WPF中,您可以将Label.ToolTip元素添加到XAML代码中。

In all cases, though, there's a built-in way to do it, so it might not be necessary for you to write your own code at all.

但是,在所有情况下,都有内置的方法来执行此操作,因此您可能根本不需要编写自己的代码。

If your situation is so custom that you do need to write your own code, I'd really need to know more about how you are representing the numbers in your calendar to help you out.

如果你的情况是如此自定义,你需要编写自己的代码,我真的需要了解更多关于你如何表示日历中的数字来帮助你。

Last thing: you didn't really ask this--and it may not be under your control--but you might want to ask yourself whether a tooltip is the best way to show calendar information in the first place. If space is really tight, then the answer might be "yes", but if you have enough space to show the calendar events (or even the first few words of each event), this would save the user from having to "scrub the whole calendar" (i.e., roll over each date individually).

最后一件事:你并没有真正问过这个 - 它可能不在你的控制之下 - 但是你可能想问问自己,工具提示是否是首先显示日历信息的最佳方式。如果空间非常紧张,那么答案可能是“是”,但是如果你有足够的空间来显示日历事件(甚至每个事件的前几个单词),这将使用户不​​必“擦洗整个日历“(即,单独滚动每个日期)。

-Dan

#3


Have a look at the AutoPopDelay, InitialDelay and ReshowDelay properties of the ToolTip class, as they control the behaviour of the tooltip.

查看ToolTip类的AutoPopDelay,InitialDelay和ReshowDelay属性,因为它们控制工具提示的行为。

I generally play around with the values until I get something that 'feels' right. It's annoying when a tooltip shows immediately, and for short tooltips, it's also annoying when they disappear too soon. For really long tooltips, say, several paragraphs (yes, poor design decision, but if there's a lot of info to read, at least let me read it!) then it should stay open as long as my mouse is stationary.

我通常会玩弄价值观,直到我得到“感觉”正确的东西。当工具提示立即显示时很烦人,而对于简短的工具提示,当它们过早消失时它也很烦人。对于很长的工具提示,比如几个段落(是的,糟糕的设计决定,但如果有很多信息需要阅读,至少让我读一读!)那么只要我的鼠标静止就应该保持打开状态。

A tooltip example from MSDN gives the following values:

MSDN中的工具提示示例提供以下值:

 AutoPopDelay = 5000;
 InitialDelay = 1000;
 ReshowDelay = 500;
 // Force the ToolTip text to be displayed whether or not the form is active.
 ShowAlways = true;

As mentioned in a comment, the poster wants to trigger the tooltip programatically. For that, ToolTip.Show( ) needs to be called. To get a delay effect, you'll likely want to have a timer running which counts the time that the mouse is stationary. Whenever the mouse enters, leaves or moves within the control, this time should be reset.

正如评论中所提到的,海报希望以编程方式触发工具提示。为此,需要调用ToolTip.Show()。要获得延迟效果,您可能希望运行一个计时器来计算鼠标静止的时间。只要鼠标在控件内进入,离开或移动,就应该重置此时间。