1

i wanted to show balloon tooltip when mouse over on listview item. so i write the below code but the problem is when tooltips is showing then huge flickering is occuring. how to stop it. please guide. thanks

 private void treeListView1_MouseMove(object sender, MouseEventArgs e)
        {
            ListViewItem item = treeListView1.GetItemAt(e.X, e.Y);
            ListViewHitTestInfo info = treeListView1.HitTest(e.X, e.Y);

            if ((item != null) && (info.SubItem != null))
            {
                toolTip1.Show(info.SubItem.Text, this.treeListView1);
            }
            else
            {
                toolTip1.Hide(this.treeListView1);
            }
        }
Thomas
  • 33,544
  • 126
  • 357
  • 626

1 Answers1

2

It can be useful to memorize the last mouse position and only re-show the tooltip if the position has changed. Otherwise you permanently show the tooltip when the event occurs. Example:

private Point LastMousePos = new Point(-1, -1);

private void treeListView1_MouseMove(object sender, MouseEventArgs e)
{
    if (LastMousePos == e.Location)
        return;

    ListViewItem item = treeListView1.GetItemAt(e.X, e.Y);
    ListViewHitTestInfo info = treeListView1.HitTest(e.X, e.Y);

    if ((item != null) && (info.SubItem != null))
    {
        LastMousePos = e.Location;
        toolTip1.Show(info.SubItem.Text, this.treeListView1);
    }
    else
    {
        toolTip1.Hide(this.treeListView1);
    }
}
Robert S.
  • 1,942
  • 16
  • 22
  • Probably won't help much because I'm pretty sure MouseMove isn't called for the same point back to back (because in such a case the mouse didn't actually move). You're on the right track though, you'll want to probably memorize the last `ListViewItem` and/or subitem. – Anthony Jul 30 '14 at 18:00
  • In general I would agree but if I remember correctly the mouse move event is actually called multiple times for the same mouse position. But I can be wrong. But nevertheless your suggestion with the last `ListViewItem` is of course much better. But you should reset the last item in something like the `MouseLeave` or `Leave` event then. Otherwise the tooltip won't reappear after leaving and reentering the item. – Robert S. Jul 30 '14 at 19:30
  • Yes. Every time the tooltip is shown in a mousemove the same x,y fires again. If you again show the tooltip you will have an ever continuing cycle of mousemove events with the same (x,y). Not sure why this is the case, but exiting the event if x,y repeats prevents retriggering and the cycle stops. – flodis Dec 14 '20 at 20:50