我想在自定义富文本控件中,当鼠标悬停在链接上时显示提示。考虑以下文本:
我们都在夜晚睡觉。
在我的情况下,单词睡觉是一个链接。
当用户将鼠标移动到链接下方,即“睡觉”时,我想为该链接显示一个工具提示。
以下方法浮现在我的脑海中,但它们并没有起作用:
1)捕获 OnMouseHover 事件
if(this.Cursor == Cursors.Hand)
tooltip.Show(textbox,"My tooltip");
else
tooltip.Hide(textbox);
但是这个方法行不通。
更新
提到的链接不是URL,也就是说这些是自定义链接,因此正则表达式在这里帮助不大,它可以是任何文本。用户可以选择将其创建为链接。
虽然我还没有尝试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);
}
}