在文本的鼠标悬停时显示工具提示 [英] Displaying tooltip on mouse hover of a text

查看:36
本文介绍了在文本的鼠标悬停时显示工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在鼠标悬停在我的自定义 Rich Edit 控件中的链接上时显示工具提示.考虑以下文本:

I want to display a tooltip when the mouse hovers over a link in my custom rich edit control. Consider the following text:

我们都在晚上睡觉.

就我而言,sleep 这个词是一个链接.

In my case the word sleep is a link.

当用户在链接下移动鼠标时,在本例中为sleep",我想显示链接的工具提示.

When the user moves the mouse under the link, in this case "sleep", I want to display a tooltip for the link.

我想到了以下内容,但它们不起作用

The following came to my mind, but they are not working

1) 捕获 OnMouseHover

1) Trapping OnMouseHover

if(this.Cursor == Cursors.Hand)
   tooltip.Show(textbox,"My tooltip");
else
   tooltip.Hide(textbox);

但这行不通.

更新

提到的链接是不是 URL,即这些是自定义链接,因此正则表达式在这里没有太大帮助,它可以是任何文本.用户可以选择创建一个链接.

The links mentioned are not URLs, i.e these are custom links, so Regex won't be of much help here, it can be any text. The user can choose to create it a a link.

虽然我没有尝试过 GetPosition 方法,但我认为它在设计和维护方面不会那么优雅.

Though I have not tried GetPosition method, I dont think it would be that elegant in terms of design and maintenance.

让我说我的richedit框中有以下行

Let me say I have the following line, in my richedit box

我们在晚上睡觉.但蝙蝠保持清醒.蟑螂在晚上变得活跃.

We sleep at night. But the bats stay awake. Cockroaches become active at night.

在上面的句子中,我想要三个不同的工具提示,当鼠标悬停在它们上面时.

In the above sentence, I want three different tooltips, when the mouse hovers over them.

sleep -> Human beings
awake -> Nightwatchman here
active -> My day begins

我将OnMouseMove 捕获如下:

使用 Messagebox

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 工具从工具箱添加到表单中,然后将此代码添加到任何您想让工具提示在其 mousemove 上开始的控件的 mousemove 事件中

Just add ToolTip tool from toolbox to the form and add this code in a mousemove event of any control you want to make the tooltip start on its mousemove

private void textBox3_MouseMove(object sender, MouseEventArgs e)
    {
      toolTip1.SetToolTip(textBox3,"Tooltip text"); // you can change the first parameter (textbox3) on any control you wanna focus
    }

希望能帮到你

和平

这篇关于在文本的鼠标悬停时显示工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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