Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 449
Amir Saniyan Avatar asked Dec 12 '25 15:12

Amir Saniyan


2 Answers

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.

like image 86
bitoshi.n Avatar answered Dec 15 '25 05:12

bitoshi.n


  • Register an OnMouseMove handler
  • Call GetCharIndexFormPosition
  • Determine if that index is over a bolded character
  • Set the Cursor property as desired.
like image 36
shf301 Avatar answered Dec 15 '25 05:12

shf301