防止只读 RichTextBox 出现闪烁光标 (IBeam)
每当文本框获得焦点时,是否有办法防止只读 RichRextBox
的光标(IBeam)闪烁?
我尝试阻止来自 WndProc
的 WM_SETFOCUS
消息,但它导致表单挂起。
if( m.Msg == 0x0007 ) return;
Is there anyway to prevent the cursor (IBeam) of a read-only RichRextBox
from blinking whenever the textbox got focus?
I've tried to block the WM_SETFOCUS
message from the WndProc
but it causes the form to hang.
if( m.Msg == 0x0007 ) return;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要使用 Win32 API。 以下是您可以在 VB 中执行的操作:
在 C# 中,
进行调用。
然后在您想要隐藏它时
You'll need to use Win32 APIs. Here's what you could do in VB:
and in C#
then make a call to
when ever you want to hide it.
只是说 Anirudh Goel 的答案不起作用(至少在 C# 中)。 克拉仍然闪烁:/
我在以下位置找到了解决方案: http://www.experts-exchange .com/Programming/Languages/C_Sharp/Q_21896403.html
他的类总是隐藏插入符号,这里是一个改进的类,因此您可以选择隐藏或不隐藏插入符号。
如果你想隐藏,请不要忘记将 MustHideCaret 设置为 true
Just to say that the Anirudh Goel answer does not work (at least in C#). The carat still there blinking :/
I found a solution at: http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_21896403.html
His class always hide the caret, here is an improved one so you can choose to hide or not the caret.
If you want to hide do not forget to set MustHideCaret to true
更简单的方法:将此事件附加到 RichTextBox 的 Enter 事件中:
Easier method: attach this event to the Enter event of the RichTextBox:
对我来说 Pedro77 的解决方案也不起作用......
我已将该类修改为:
然后将我的 RichTextBoxEx 放入(内部)面板控件中...
修复了单击鼠标时闪烁插入符号的问题...
For me solution from Pedro77 didn't work too...
I've modified that class to:
then put my RichTextBoxEx into (inside) Panel control...
that fixed getting blinking caret on mouse click...
经过多次尝试和错误,我找到了简单的解决方案。
在表单的“加载”子例程中,添加以下行:
然后将以下内容添加到表单代码的底部。 规定您希望在“HideCaret”例程中发生“阻止进入”的控件
(我列出了属于我的表单的三个文本框):
最后将其放置在表单代码的顶部(在类名称和第一个子或函数之间):
然后,当用户单击控件列表中显示的任何控件时在“HideCaret”例程中,光标只是停留在先前选择的控件中。
VB.Net 不是很棒吗? 你几乎可以实现任何你认为不可能的事情。
After much trial and error, I have found the simple solution.
In your form's "Load" subroutine, add the line:
Then add to the bottom of your form's code the following. Stipulate the controls on which you wish this "blocking of entry" to occur in the "HideCaret" routine
(I have listed three textboxes belonging to my form):
and finally place at the top of your form code (between the Class name and the first sub or function the following:
Then when the user clicks on any control shown in the list of controls in the "HideCaret" routine, the cursor simply stays in the previously selected control.
Isn't VB.Net wonderful? You can achieve almost anything you thought not possible.