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.
Add your tooltip by selecting the Tooltip option on the Marks shelf. Navigate to the dashboard where you want the tooltip and place the visual that you created in this blog post over the appropriate textbox. You should now have a textbox with a tooltip that appears when you hover over it.
HTML: Use a container element (like <div>) and add the "tooltip" class to it. When the user mouse over this <div>, it will show the tooltip text. The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" .
Single element To make an element display its tooltip permanently, we use its showTooltipOn property. To make tooltip always be shown, set it to "always" .
In Visual Studio, add a ToolTip component to the form. Select the control that will display the ToolTip, or add it to the form. In the Properties window, set the ToolTip on ToolTip1 value to an appropriate string of text.
Hook into the textbox.enter event and use the following code:
private void textBox1_Enter(object sender, EventArgs e) { TextBox TB = (TextBox)sender; int VisibleTime = 1000; //in milliseconds ToolTip tt = new ToolTip(); tt.Show("Test ToolTip",TB,0,0,VisibleTime); }
Play with X/Y values to move it where you want. Visible time is how long until it disappears.
Tooltips only appear when the mouse is still by design.
You could try setting the InitialDelay
to 0:
tt.InitialDelay = 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.
you can show a tooltip also like this:
ToolTip t = new ToolTip();
t.Show("Hello World", textBox1, 1000);
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
private void procToolTips(object sender, EventArgs e)
{
ToolTip tt = new ToolTip();
Control o = (Control)sender;
if ( o.Name == "label1") {
tt.Show("Lorem ipsum dolor sit ame", o, 1000);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With