6

I am trying to get a tooltip to display on a disabled textbox during a mouse over. I know because the control is disabled the following won't work:

private void textBox5_MouseHover(object sender, EventArgs e)
{
       // My tooltip display code here
}

How can I get the tooltip to display on a mouse over of a disabled control?

Many thanks

3 Answers 3

17

MouseHover wont fire if control is disabled. Instead you can check in Form MouseMove event whether you hover the textbox

    public Form1()
    {
        InitializeComponent();
        textBox1.Enabled = false;
        toolTip.InitialDelay = 0;
    }

    private ToolTip toolTip = new ToolTip();
    private bool isShown = false;

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        if(textBox1 == this.GetChildAtPoint(e.Location))
        {
            if(!isShown)
            {
                toolTip.Show("MyToolTip", this, e.Location);
                isShown = true;
            }
        }
        else
        {
            toolTip.Hide(textBox1);
            isShown = false;
        }
    }

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

One further thought - how would this be applied to a textbox within a groupbox?
then you should sign for groupBox MouseMove Event and do the same thing as for Form
This is can be more reliable: textBox1.Name == this.GetChildAtPoint(e.Location).Name
0

Late to the party, but had the same problem and found a better solution: you can just wrap your TextBox in another Item and put a ToolTip on it like:

<Grid ToolTip="ToolTip to display">
            <TextBox  IsEnabled="False" Text="Text to display" />
</Grid>

Comments

-1

You can also drag a ToolTip object from the Toolbox in designer onto the form. Then in the code you just call SetToolTip() and pass in the button or text box etc. you want the tool tip to assign to and the text you want it to show.

myToolTip.SetToolTip(myTextBox, "You just hovered over myTextBox!");

1 Comment

Except when the control is disabled you won't see a tool tip. That's the point of his question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.