3
當鼠標指針位於RichTextBox中的黑體字上時,我想將光標更改爲HAND。這個怎麼做?如何在鼠標指針位於RichTextBox中的粗體字上時更改光標?
當鼠標指針位於RichTextBox中的黑體字上時,我想將光標更改爲HAND。這個怎麼做?如何在鼠標指針位於RichTextBox中的粗體字上時更改光標?
將此函數添加到richtextbox.OnMouseMove事件中。
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;
}
}
你只需要1個字符就可以知道它是否爲粗體。
感謝您的回答,但我的問題是第3步(•確定該索引是否超過粗體字符),如何確定而不更改SelectionStart和SelectionLength? –