1
votes

I am trying to add tool tip to a dithered textbox in winform. For adding the tooltip, mouse hover event is needed but in case of dithered text box, mouse hover event doesn't fire. Is there any other way to add tooltip for mouse hovering?

When the user hovers over this dithered textbox, the entire content of textbox should display in tooltip.

2
What do you mean by a dithered TextBox? - Reza Aghaei
'TextBox' which is not editable and on which control can't go. It basically behaves as a 'Label'. - Nikhil Kumar
Do you set Enabled=false or setReadOnly=true? - Reza Aghaei
Enabled is set to false and ReadOnly is set to true. - Nikhil Kumar
Set enabled to true and try suggestion - Reza Aghaei

2 Answers

1
votes

ToolTip doesn't show for TextBox the first time that mouse hovers on it.

It seems the tooltip for TextBox only appears on second hover event. It doesn't matter whether the TextBox is ReadOnly or not. But as a workaround, you can handle MouseHover and MouseLeave events yourself and write such code:

private void textBox1_MouseHover(object sender, EventArgs e)
{
    var point = this.textBox1.PointToClient(Cursor.Position);
    point.Offset(0, 20);
    this.toolTip1.Show("Some Text", this.textBox1,
        point, 2000);
}
private void textBox1_MouseLeave(object sender, EventArgs e)
{
    this.toolTip1.Hide(this.textBox1);
}

Here is the screenshot of behavior before fix:

enter image description here

Screenshot after fix:

enter image description here

0
votes

Try the following code:

        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.