显示工具提示过禁用的控件 [英] Displaying tooltip over a disabled control

查看:120
本文介绍了显示工具提示过禁用的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,当鼠标悬停在禁用的控件显示一个提示。由于禁用控件不处理任何事件,我必须这样做,在父窗体。我选择了通过处理父窗体的的MouseMove 事件来做到这一点。这里的code,没有工作:

I'm trying to display a tooltip when mouse hovers over a disabled control. Since a disabled control does not handle any events, I have to do that in the parent form. I chose to do this by handling the MouseMove event in the parent form. Here's the code that does the job:

    void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        m_toolTips.SetToolTip(this, "testing tooltip on " + DateTime.Now.ToString());
        string tipText = this.m_toolTips.GetToolTip(this);
        if ((tipText != null) && (tipText.Length > 0))
        {
            Point clientLoc = this.PointToClient(Cursor.Position);
            Control child = this.GetChildAtPoint(clientLoc);
            if (child != null && child.Enabled == false)
            {
                m_toolTips.ToolTipTitle = "MouseHover On Disabled Control";
                m_toolTips.Show(tipText, this, 10000);
            }
            else
            {
                m_toolTips.ToolTipTitle = "MouseHover Triggerd";
                m_toolTips.Show(tipText, this, 3000);
            }
        }
    }

在code做处理残疾人控制工具提示的显示。问题是,当鼠标悬停在禁用的控件,工具提示一直关闭,并再次重新显示。从显示的时间我在提示补充说,当鼠标父窗体上方时,的MouseMove 事件被称为每3秒粗略,所以提示得到每3秒更新一次。但是,当鼠标在禁用控制工具提示刷新间隔1秒。此外,当提示刷新上面的形式,只有文字被用短暂闪烁更新。但是,当提示刷新禁用的控制上面,工具提示窗口将关闭,如果鼠标移动到启用了控制和工具提示应该被关闭。但随后再次出现提示马上

The code does handles the tooltip display for the disabled control. The problem is that when mouse hovers over a disabled control, the tooltip keeps closing and redisplay again. From the display time I added in the tooltip, when mouse is above the parent form, the MouseMove event gets called roughly every 3 seconds, so the tooltip gets updated every 3 seconds. But when mouse is over a disabled control, the tooltip refreshes every 1 second. Also, when tooltip refreshes above form, only the text gets updated with a brief flash. But when tooltip refreshes above a disabled control, the tooltip windows closes as if mouse is moving into a enabled control and the tooltip is supposed to be closed. but then the tooltip reappears right away.

谁能告诉我这是为什么?谢谢你。

Can someone tell me why is this? Thanks.

推荐答案

答案竟然是有点简单,但需要在任何时候都适用。

The answer turned out to be a bit simpler, but needed to be applied at all times.

void OrderSummaryDetails_MouseMove(object sender, MouseEventArgs e)
{
      Control control = GetChildAtPoint(e.Location);
      if (control != null)
      {
          string toolTipString = mFormTips.GetToolTip(control);
          this.mFormTips.ShowAlways = true;
          // trigger the tooltip with no delay and some basic positioning just to give you an idea
          mFormTips.Show(toolTipString, control, control.Width / 2, control.Height / 2);
      }
}

这篇关于显示工具提示过禁用的控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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