【发布时间】:2010-10-26 18:26:40
【问题描述】:
当鼠标悬停在我的自定义富编辑控件中的链接上时,我想显示一个工具提示。考虑以下文本:
我们都在晚上睡觉。
在我的例子中,sleep这个词是一个链接。
当用户在链接下移动鼠标时,在本例中为“睡眠”,我想显示链接的工具提示。
我想到了以下内容,但它们不起作用
1) 捕获 OnMouseHover
if(this.Cursor == Cursors.Hand)
tooltip.Show(textbox,"My tooltip");
else
tooltip.Hide(textbox);
但这行不通。
更新
提到的链接是不是 URL,即这些是自定义链接,因此 Regex 在这里不会有太大帮助,它可以是任何文本。用户可以选择创建一个链接。
虽然我没有尝试过GetPosition的方法,但我认为它在设计和维护方面不会那么优雅。
让我说我在我的 Richedit 框中有以下行
我们在晚上睡觉。但是蝙蝠保持清醒。蟑螂在晚上变得活跃。
在上面的句子中,当鼠标悬停在它们上方时,我想要三个不同的工具提示。
sleep -> Human beings
awake -> Nightwatchman here
active -> My day begins
我将OnMouseMove困如下:
使用消息框
OnMouseMove( )
{
// check to see if the cursor is over a link
// though this is not the correct approach, I am worried why does not a tooltip show up
if(this.Cursor.current == Cursors.hand )
{
Messagebox.show("you are under a link");
}
}
不工作 - 使用工具提示 - 工具提示不显示
OnMouseMove( MouseventArgs e )
{
if(cursor.current == cursors.hand )
{
tooltip.show(richeditbox,e.x,e.y,1000);
}
}
【问题讨论】:
-
这成功了.. tooltip.Active = true
-
哦,我没有意识到你的问题是工具提示本身......无论如何,使用 System.Windows.Forms.Cursor.Current 静态获取当前鼠标光标,就像我上一个答案一样。
标签: c# .net winforms tooltip richtextbox