gpt4 book ai didi

winforms - 防止只读的RichTextBox闪烁光标(IBeam)

转载 作者:行者123 更新时间:2023-12-04 03:02:55 26 4
gpt4 key购买 nike

无论如何,只要文本框获得焦点,是否可以防止只读RichRextBox的光标(IBeam)闪烁?

我试图阻止WM_SETFOCUS中的WndProc消息,但它导致表单挂起。

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

最佳答案

您将需要使用Win32 API。这是您可以在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)

每当您想隐藏它时。

关于winforms - 防止只读的RichTextBox闪烁光标(IBeam),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/734032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com