Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show tooltip on textbox entry

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.

like image 986
Lukas Bystricky Avatar asked Feb 04 '13 20:02

Lukas Bystricky


People also ask

How do I add a tooltip to a text box?

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.

How do I show text tooltip in HTML?

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" .

How do I make my tooltip always visible?

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" .

How do you display a tooltip?

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.


4 Answers

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.

like image 87
Lee Harrison Avatar answered Sep 27 '22 16:09

Lee Harrison


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.

like image 22
ChrisF Avatar answered Sep 27 '22 16:09

ChrisF


you can show a tooltip also like this:

ToolTip t = new ToolTip();
t.Show("Hello World", textBox1, 1000);
like image 31
lamiinek Avatar answered Sep 27 '22 16:09

lamiinek


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);
   }
}
like image 40
user2283985 Avatar answered Sep 27 '22 16:09

user2283985