使用C#将鼠标悬停在richtextbox中的文本事件上 [英] mouse over text event in richtextbox using c#

查看:328
本文介绍了使用C#将鼠标悬停在richtextbox中的文本事件上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在富文本框中使用鼠标悬停事件.
当鼠标悬停在某些文本上时,该文本将存储在某个变量中以备将来使用.

I want to use a mouse over event in rich text box.
When the mouse is over some text that text is to be store in some variable for future use.

推荐答案

private void richTextBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

// Determine whether the user clicks the left mouse button and whether it is a double click.
            if (e.Clicks == 1 && e.Button == MouseButtons.Left)
            {
                // Obtain the character index where the user clicks on the control.
                int positionToSearch = richTextBox1.GetCharIndexFromPosition(new Point(e.X, e.Y));



但是您可以使用MouseOver事件代替MouseDown.
从这一点出发,如果您有此位置,则可以从它的左右获取文本,并使用正则表达式找出它是否是鼠标所在的词.

我有这个例子:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.getcharindexfromposition.aspx [ ^ ]

我还认为有人已经使用MouseOver事件实现了这一点:

http://forums.devx.com/showthread.php?t=143645 [ ^ ]



but instead of MouseDown you would use the MouseOver event.
and from that point, if you have the position, you could get text from the left and right of it, and use regular expressions to find out if it is a word your mouse is at.

I have it from this example:
http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.getcharindexfromposition.aspx[^]

I also think that someone has implemented this already using a MouseOver event:

http://forums.devx.com/showthread.php?t=143645[^]


这篇关于使用C#将鼠标悬停在richtextbox中的文本事件上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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