防止来自只读 RichTextBox 的闪烁光标 (IBeam) [英] Prevent Blinking Cursor (IBeam) from a Read-Only RichTextBox

查看:63
本文介绍了防止来自只读 RichTextBox 的闪烁光标 (IBeam)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何要防止只读 RichRextBox 的光标 (IBeam) 在文本框获得焦点时闪烁?

Is there anyway to prevent the cursor (IBeam) of a read-only RichRextBox from blinking whenever the textbox got focus?

我试图阻止来自 WndProcWM_SETFOCUS 消息,但它导致表单挂起.

I've tried to block the WM_SETFOCUS message from the WndProc but it causes the form to hang.

if( m.Msg == 0x0007 ) return;

推荐答案

您需要使用 Win32 API.以下是您可以在 VB 中执行的操作:

You'll need to use Win32 APIs. Here's what you could do in VB:

'API declares
Private Declare Function HideCaret Lib "user32" _
(ByVal hwnd As IntPtr) As Integer
Private Declare Function ShowCaret Lib "user32" _
(ByVal hwnd As IntPtr) As Integer
'hide the caret in myTextBox
Call HideCaret(myTextBox.Handle)
'show the caret back..
Call ShowCaret(myTextBox.Handle)

在 C# 中

 [DllImport("user32.dll", EntryPoint = "ShowCaret")]
 public static extern long ShowCaret(IntPtr hwnd);
 [DllImport("user32.dll", EntryPoint = "HideCaret")]
 public static extern long HideCaret(IntPtr hwnd);

然后打电话给

   HideCaret(richtextbox.Handle)

当你想隐藏它时.

这篇关于防止来自只读 RichTextBox 的闪烁光标 (IBeam)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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