RichTextBox光标不断更改为IBeam [英] RichTextBox cursor keeps changing to IBeam

查看:156
本文介绍了RichTextBox光标不断更改为IBeam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只读的 RichTextBox ,其光标设置为 Arrow 。即使如此,当我将其悬停时,光标也会闪烁,并在 Arrow IBeam 之间快速切换。如何使其保持在箭头而不闪烁?

I have a readonly RichTextBox, with its cursor set to Arrow. Even so, when I hover it, the cursor flickers, and switches very quickly between Arrow and IBeam. How can I make it stay on Arrow and not flicker?

推荐答案

我假设这是WinForms RichTextBox,因为WPF没有这个问题

I'm assuming this is the WinForms RichTextBox, because the WPF one doesn't have this problem.

RichTextBox可以处理 WM_SETCURSOR 消息,如果鼠标指针最终出现在链接上,则将Cursor更改为 Cursors.Hand 。开发人员的注释:

The RichTextBox handles WM_SETCURSOR messages, to change the Cursor to Cursors.Hand if the Mouse Pointer ends up on a Link. A note from the developers:


RichTextBox在链接上使用 WM_SETCURSOR 消息来允许我们将
更改为手形。它通过同步
通知消息来完成此操作。因此,我们必须先将消息传递给DefWndProc
,然后,如果在此期间我们收到通知消息
(通过更改 LinkCursor表示,则将其设置为手形。否则,将
我们在Control上调用 WM_SETCURSOR 实现,将其设置为RichTextBox光标的
用户选择。

RichTextBox uses the WM_SETCURSOR message over links to allow us to change the cursor to a hand. It does this through a synchronous notification message. So we have to pass the message to the DefWndProc first, and then, if we receive a notification message in the meantime (indicated by changing "LinkCursor", we set it to a hand. Otherwise, we call the WM_SETCURSOR implementation on Control to set it to the user's selection for the RichTextBox's cursor.

您可以在鼠标进入控件的边界时设置捕获,然后在鼠标指针离开该区域时释放它,否则,当您第一次单击另一个捕获时,需要释放捕获控件,则将光标设置为RichTextBox:

You could set the Capture when the Mouse enters the Control's bounds and then release it when the Mouse Pointer leaves the area. The capture needs to be released otherwise, when you first click on another control, the cursor will be set to RichTextBox instead:

private void richTextBox1_MouseMove(object sender, MouseEventArgs e)
{
    if (!richTextBox1.ClientRectangle.Contains(e.Location))
    {
        richTextBox1.Capture = false;
    }
    else if (!richTextBox1.Capture)
        richTextBox1.Capture = true;
}

这篇关于RichTextBox光标不断更改为IBeam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆