3
votes

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

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.

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

What's the best way to do this?

EDIT:I'm using WinForms

3

3 Answers

6
votes

The time delay between Enter and Hover is specified in 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".

0
votes

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

  • 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.
  • In Forms, I think you have to actually create a ToolTip object then attach a control to it.
  • In WPF, you can add a Label.ToolTip element to your XAML code.

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

0
votes

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

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:

 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.