以下代码避免了Richtextbox的重点。因此用户无法编辑文本或选择它。为了避免Cursor更改为 IBeam ,我还会捕获 SETCURSOR消息。但问题是,richtextbox还包含链接,如果我将鼠标移到链接上,我希望光标更改为 Hand 。所以我必须区分 IBeam 和 Hand 。为此,我找不到解决方案,尽管我认为这不会那么困难。
Const WM_SETFOCUS = &H0007
Const WM_KILLFOCUS = &H0008
Const WM_SETCURSOR = &H0020
Const WM_NULL = &H0000
Protected Overrides Sub WndProc(ByRef _M As Message)
Select Case _M.Msg
Case WM_SETFOCUS, WM_KILLFOCUS
_M.Msg = WM_NULL
Case WM_SETCURSOR
'Here I need your help: How can I check the cursor?
'If Cursor is IBeam Then
' _M.Msg = WM_NULL
'End If
End Select
MyBase.WndProc(_M)
End Sub
答案 0 :(得分:0)
这适用于C#但你应该能够转换它:
protected override void OnMouseMove(MouseEventArgs e)
{
if (SelectionLength > 0)
{
int position = GetCharIndexFromPosition(e.Location);
if (position > SelectionStart && position < SelectionStart+SelectionLength)
this.Cursor = Cursors.Arrow;
else
this.Cursor = Cursors.IBeam;
}
base.OnMouseMove(e);
}