显示工具提示过禁用的控件

编程入门 行业动态 更新时间:2024-10-28 20:27:57
本文介绍了显示工具提示过禁用的控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想,当鼠标悬停在禁用的控件显示一个提示。由于禁用控件不处理任何事件,我必须这样做,在父窗体。我选择了通过处理父窗体的的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); } }

更多推荐

显示工具提示过禁用的控件

本文发布于:2023-11-03 17:00:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   提示   工具

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!