Displaying tooltip on mouse hover of a text

前端 未结 9 1014
盖世英雄少女心
盖世英雄少女心 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:04

    Use:

    ToolTip tip = new ToolTip();
    private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
    {
        Cursor a = System.Windows.Forms.Cursor.Current;
        if (a == Cursors.Hand)
        {
            Point p = richTextBox1.Location;
            tip.Show(
                GetWord(richTextBox1.Text,
                    richTextBox1.GetCharIndexFromPosition(e.Location)),
                this,
                p.X + e.X,
                p.Y + e.Y + 32,
                1000);
        }
    }
    

    Use the GetWord function from my other answer to get the hovered word. Use timer logic to disable reshow the tooltip as in prev. example.

    In this example right above, the tool tip shows the hovered word by checking the mouse pointer.

    If this answer is still not what you are looking fo, please specify the condition that characterizes the word you want to use tooltip on. If you want it for bolded word, please tell me.

提交回复
热议问题