I have a textbox
that requires data to be entered in a certain way. I have implemented some cell validating techniques to check the data after it has been entered, but I'd like to provide the user with some information before they enter the data.
To that end, I'd like to add a tooltip
to the textbox
that pops up when the user enters the toolbox, then exits when they begin to type.
For example I have the following code:
private void YearEdit_Enter(object sender, EventArgs e)
{
ToolTip tt = new ToolTip();
tt.IsBalloon = true;
tt.InitialDelay = 0;
tt.ShowAlways = true;
tt.SetToolTip(YearEdit, "Enter 4 digit year.");
}
This executes when the user enters the textbox
, however the tooltip
only appears when the mouse hovers over the textbox
. Does anyone have any ideas to work around this? I thought that perhaps tt.ShowAlways = true
might work, but obviously not.
Tooltips only appear when the mouse is still by design.
You could try setting the
InitialDelay
to 0:But this would still require the mouse to be stationary for an instant.
However there are other approaches. A common way of showing what input is required is to use a watermark (faded text) in the textbox that displays the formatting required until the user starts typing.
If you really want a tooltip then you could either add an information icon (usually an "i") which will show the tooltip when it's hovered over, or implement your own.
It might also work if you break the date into parts (separate day, month, year). This will allow you more control over what the user can enter - the month can become a drop down/combo box so it's always the correct format.
Hook into the textbox.enter event and use the following code:
Play with X/Y values to move it where you want. Visible time is how long until it disappears.
you can show a tooltip also like this:
Try this. (based on an answer above) Add event handlers for all controls that you want to have a ToolTip for. Point all the event handlers to the same method. Then construct you handling method like this