Displaying tooltip on mouse hover of a text

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

    If you are using RichTextBox control. You can simply define the ToolTip object and show the tool-tip as the text is selected by moving the mouse inside the RichTextBox control.

        ToolTip m_ttInput = new ToolTip(); // define as member variable
    
        private void rtbInput_SelectionChanged(object sender, EventArgs e)
        {
            if (rtbInput.SelectedText.Length > 0) 
            {
                m_ttInput.Show(rtbInput.SelectedText.Length.ToString(), rtbInput, 1000);
            }
        }
    

提交回复
热议问题