问题
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