views:

746

answers:

1

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;
+1  A: 

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)

and in 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);

then make a call to

   HideCaret(richtextbox.Handle)

when ever you want to hide it.

Anirudh Goel