Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display a tooltip when focus is in a specific textbox?

For a textbox, I want to display a tooltip immediatly when the focus is in on the textbox, and stay there for the duration of the focus - not just when the mouse hovers over the textbox.

enter image description here

How can I do that?

like image 570
Kjensen Avatar asked Dec 14 '11 20:12

Kjensen


Video Answer


4 Answers

Windows Forms

public partial class FormWindow : Form
{
        //Constructor
        public FormWindow()
        {
            txtUrl.Text = "Enter text here";
            txtUrl.ForeColor = Color.Gray;
            txtUrl.GotFocus += TxtUrl_GotFocus;
            txtUrl.LostFocus += TxtUrl_LostFocus;
        }

        private void TxtUrl_GotFocus(object sender, EventArgs e)
        {
            txtUrl.Text = "";
            txtUrl.ForeColor = Color.Black;
        }

        private void TxtUrl_LostFocus(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtUrl.Text))
            {
                txtUrl.Text = "Enter text here";
                txtUrl.ForeColor = Color.Gray;
            }
        }
}
like image 182
Amol Bhor Avatar answered Nov 02 '22 06:11

Amol Bhor


The Enter and Leave events are probably useful here, and show it with a duration of 0 to keep it there.

private ToolTip tt;

private void textBox1_Enter(object sender, EventArgs e) {
  tt = new ToolTip();
  tt.InitialDelay = 0;
  tt.IsBalloon = true;
  tt.Show(string.Empty, textBox1);
  tt.Show("I need help", textBox1, 0);
}

private void textBox1_Leave(object sender, EventArgs e) {
  tt.Dispose();
}

Note: Calling the Show(...) method twice like in my example will force the "pointer" to point correctly to the control.

like image 39
LarsTech Avatar answered Nov 02 '22 05:11

LarsTech


have tested, the event names:

   private void textbox_Enter(object sender, EventArgs e)
    {
        toolTip1.Show("your tip here", textbox);

    }

    private void textbox_Leave(object sender, EventArgs e)
    {
        toolTip1.Hide(textbox);

    } 

tooltip is a control, needs to be added from toolbox.

like image 36
Bernd at New Orleans Avatar answered Nov 02 '22 05:11

Bernd at New Orleans


using mouse hover and mouse leave events

    private void textBox1_MouseHover(object sender, EventArgs e)
    {
        toolTip1.Show("your tip here", textBox2);

    }

    private void textBox1_MouseLeave(object sender, EventArgs e)
    {
        toolTip1.Hide(textBox2);
    }

>

like image 28
Nana Yaw Zaza Oduro Avatar answered Nov 02 '22 05:11

Nana Yaw Zaza Oduro