0

RichTextBox有没有办法使用事件来确定文本的颜色mousemove?我想避免使用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;
}
4

2 回答 2

1

您可以尝试这样的事情,从JoOls的这个MSDN 论坛答案修改,它将为您提供鼠标下方像素的颜色。

private void rtbComputerstatus_MouseMove(object sender, MouseEventArgs e)
{
    Point  cursorPoint = Cursor.Position;
    Bitmap bm = new Bitmap(1, 1);
    Graphics g  = Graphics.FromImage(bm);
    g.CopyFromScreen(cursorPoint, new Point(), new Size(1, 1));
    Color pixelColor = bm.GetPixel(0, 0);
    g.Dispose();
    bm.Dispose();
    if (pixelColor.ToArgb().Equals(Color.Blue.ToArgb()))
    {
        if (rtbComputerstatus.Cursor != Cursors.Hand)
            rtbComputerstatus.Cursor = Cursors.Hand;
    }
    else
    {
        if(rtbComputerstatus.Cursor != Cursors.Default)
            rtbComputerstatus.Cursor = Cursors.Default;
    }
}
于 2013-05-10T02:30:07.833 回答
0

只是在黑暗中拍摄,但以下工作会奏效吗?

    private void rtbComputerstatus_MouseMove(object sender, MouseEventArgs e)
    {
        if (rtbComputerstatus.ForeColor.ToKnownColor() == KnownColor.Blue)
            rtbComputerstatus.Cursor = Cursors.Hand;
        else
            rtbComputerstatus.Cursor = Cursors.Default;
    }

我认为这将只检查选定的文本:

    private void rtbComputerstatus_MouseMove(object sender, MouseEventArgs e)
    {

        if (rtbComputerstatus.SelectionColor.ToKnownColor() == KnownColor.Blue)
            rtbComputerstatus.Cursor = Cursors.Hand;
        else
            rtbComputerstatus.Cursor = Cursors.Default;

    }
于 2013-05-10T02:14:02.310 回答