How to change cursor when mouse pointer is over a bold word in RichTextBox?

你说的曾经没有我的故事 提交于 2020-01-04 04:30:09

问题


I want to change cursor to the HAND when mouse pointer is over a bold word in RichTextBox. How to do this?


回答1:


Add this function to richtextbox.OnMouseMove event.

private void richTextBox2_MouseMove(object sender, MouseEventArgs e)
        {
            int c = richTextBox2.GetCharIndexFromPosition(new Point(e.X, e.Y));
            richTextBox2.Select(c, 1);
            if (richTextBox2.SelectionFont.Bold)
            {
                richTextBox2.Cursor = Cursors.Hand;
            }
            else
            {
                richTextBox2.Cursor = Cursors.Default;
            }

        }

You just need 1 char to know if it is bold.




回答2:


  • Register an OnMouseMove handler
  • Call GetCharIndexFormPosition
  • Determine if that index is over a bolded character
  • Set the Cursor property as desired.


来源:https://stackoverflow.com/questions/10476325/how-to-change-cursor-when-mouse-pointer-is-over-a-bold-word-in-richtextbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!