【发布时间】:2013-05-04 15:39:11
【问题描述】:
有没有办法使用mousemove 事件来确定RichTextBox 中的文本是什么颜色?我想避免使用Richtextbox.Select,因为它会在鼠标移动的任何地方添加一个小选择栏。
private void rtbComputerstatus_MouseMove(object sender, MouseEventArgs e)
{
int c = rtbComputerstatus.GetCharIndexFromPosition(new Point(e.X, e.Y));
rtbComputerstatus.Select(c, 1);
if (rtbComputerstatus.SelectionColor == Color.Blue)
rtbComputerstatus.Cursor = Cursors.Hand;
else
rtbComputerstatus.Cursor = Cursors.Default;
}
【问题讨论】:
-
如果您将
rtbComputerstatus.Select(c, 1);更改为rtbComputerstatus.Select(c, 0);,那么您至少不会看到蓝色的大选择框,即使您的鼠标在框周围出现插入符号也是如此。 -
这可行,有没有办法只在富文本框中隐藏插入符号?
-
可能。我知道可以使用 Windows API 来完成。不过,老实说,最好还是采用 Mark Hall 的解决方案。
标签: c# colors richtextbox mousemove