Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
woutercx 22-Jul-12 6:55am    
Are you using a WPF or Windows Forms solution?

1 solution

C#
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));


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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900