RichTextBox and keyword tooltipping...

C

Chris Shepherd

Hello group,

I'm in the conceptual phase of this, and I'm wondering what the best way
to accomplish this is. I want to do the following using a RichTextBox:

- Highlight all occurrences of any search terms with a specific colour
and italics. I already am aware of how to do this.
- When the user mouses over the highlighted word, I would like a small
predefined note regarding this to pop up tooltip style. An example might
be the word Widget. It would be highlighted, and upon mousing over some
small information about Widget would pop up (weight, dimensions,
quantity, etc.).
- Using some predefined mouse/keyboard key/click combination, trigger an
eventhandler so that the classes using this class can act on the keyword
(opening up a new information window about the widget with more details,
maybe a picture, etc.).

I think I've got a good handle on how to do the first and third parts,
but the second bit is what's not so clear. I'm thinking that I'd have to
actually suppress the normal ToolTip functionality of the RichTextBox
until I know the mouse is simply over top of a keyword, then un-suppress
it.

I haven't had a lot of time to fiddle around with this though, so the
answer may be much more obvious, and if it is, I apologize in advance
for asking silly questions. :)

Chris.
 
N

Nicholas Paldino [.NET/C# MVP]

Chris,

I would use a ToolTip control and then just hook up to the Popup event.
In it, you can cancel the tooltip if it is not over a location (you can keep
track of the mouse location and then see if you are over something
highlighted before the tip pops up) and then adjust the tooltip based on the
highlighted item if it is over something that needs a tooltip.
 
C

Chris Shepherd

Nicholas said:
Chris,

I would use a ToolTip control and then just hook up to the Popup event.
In it, you can cancel the tooltip if it is not over a location (you can keep
track of the mouse location and then see if you are over something
highlighted before the tip pops up) and then adjust the tooltip based on the
highlighted item if it is over something that needs a tooltip.

Yeah, shortly after I saw this I went and looked up the ToolTip class. I
kind of foolishly assumed that since ToolTips were also a Control
property there wouldn't be much more flexibility using the class itself.

Thanks!

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top