Displaying tooltip on mouse hover of a text

前端 未结 9 1036
盖世英雄少女心
盖世英雄少女心 2020-11-29 07:22

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

We all sleep

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 08:13

    This is not elegant, but you might be able to use the RichTextBox.GetCharIndexFromPosition method to return to you the index of the character that the mouse is currently over, and then use that index to figure out if it's over a link, hotspot, or any other special area. If it is, show your tooltip (and you'd probably want to pass the mouse coordinates into the tooltip's Show method, instead of just passing in the textbox, so that the tooltip can be positioned next to the link).

    Example here: http://msdn.microsoft.com/en-us/library/system.windows.forms.richtextbox.getcharindexfromposition(VS.80).aspx

提交回复
热议问题