Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mousehover, tooltip showing multiple times

I have a custom control (C#, visual studio). I want to show a tooltip on the mousehover event.

However, no matter what I do, it either never shows or has a chance of showing multiple times.

I thought it would be as simple as:

private void MyControl_MouseHover(object sender, EventArgs e)
{
    ToolTip tT = new ToolTip();

    tT.Show("Why So Many Times?", this);
}

But this does not work. I have tried a bunch of things but cannot seem to get it to work. I would like to have the tooltip be part of the component because I want to access private fields from it for display.

Thanks for any help

like image 730
EatATaco Avatar asked Nov 03 '09 16:11

EatATaco


2 Answers

Have you tried instantiating the tooltip in your constructor and showing it on the mouse hover?

public ToolTip tT { get; set; }

public ClassConstructor()
{
    tT = new ToolTip();
}

private void MyControl_MouseHover(object sender, EventArgs e)
{
    tT.Show("Why So Many Times?", this);
}
like image 84
Joseph Avatar answered Oct 07 '22 12:10

Joseph


The MouseHover is fired every time the mouse moves over your control. So your are creating a new tooltip every single time the event is fired. That's why you see multiple instances of this widget. Try the Joseph's answer

like image 29
Mario Avatar answered Oct 07 '22 12:10

Mario