I have a RichTextBox that contains a string, e.g: "Hello", and I want to create a new event when I hover the mouse over the word "Hello", or to simplify that, showing a message box when hover on the word "Hello". So how to achieve that?
How to make new event when hover on a text in RichTextBox?
1.8k Views Asked by kareemborai At
3
There are 3 best solutions below
0
On
I think you can use the Cursor class to achieve this. Some people tried to achieve similar things. Have a look here.
First off let's define a method that gets the word nearest to the cursor:
In order to raise
MouseMoveevent ONLY if the cursor is aboveRichTextBoxand the nearest word is"Hello"you'll need to define your own control deriving fromRichTextBoxand override theOnMouseMovemethod, and use it in your form insteadRichTextBox:However, in my opinion, it's better to let the
RichTextBoxraise theMouseMoveevent normally and take action only if conditions are met. In order to do that you only need to registerMouseMovehandler and check the conditions: