C# – How to change cursor when mouse pointer is over a bold word in RichTextBox

ccursorrichtextbox

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

Best Answer

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.