如何防止工具提示在自定义控件闪烁? [英] How to prevent tooltip from flickering in custom control?

查看:141
本文介绍了如何防止工具提示在自定义控件闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个自定义的控制,并在条件满足时,我想显示工具提示:

I have made a custom control and when a condition is met, I want to show a tooltip:

protected override void OnMouseMove(MouseEventArgs e)
{
    base.OnMouseMove(e);

    var plannedItem = GetPlannedItemByPosition(e.Location);

    if (plannedItem != null)
        _tooltip.SetToolTip(this, plannedItem.Description);
    else
        _tooltip.RemoveAll();
}

此代码工作正常,节选的工具提示闪烁的脸。

This code works fine, excepts for the face that the tooltip flickers.

这自定义控件,涂料中的的OnPaint 事件的所有信息,也许这有某种关系呢?如果是这样,我怎么能防止工具提示的闪烁?

This custom control, paints all the information in the OnPaint event, maybe this has something to do with it? And if it does, how can I prevent the tooltip from flickering?

推荐答案

这将当你在鼠标显示工具提示发生光标位置。只要提示窗口显示出来时,Windows注意到鼠标位于该窗口和职位的MouseMove消息。这使提示消失。这使得Windows传送的MouseMove消息给你的控制,运行您的OnMouseMove()方法。这使得该工具提示再次出现。 。诸如此类,你会看到提示快速闪烁

This will happen when you display the tooltip at the mouse cursor position. As soon as the tip window shows up, Windows notices that the mouse is located in that window and posts a MouseMove message. Which makes the tooltip disappear. Which makes Windows send a MouseMove message to your control, running your OnMouseMove() method. Which makes the tooltip appear again. Etcetera, you'll see the tooltip rapidly flickering.

通过以下任一方法解决这个问题:

Solve this by any of the following methods:


  • 显示工具提示从鼠标的位置得好远,所以它不会重叠鼠标光标

  • 只更新/显示工具提示需要改变时,它

  • 控件的捕获属性设置为true,以便提示不会得到的MouseMove消息

这篇关于如何防止工具提示在自定义控件闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆