Click here to Skip to main content
15,885,058 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am trying to hide the cursor in my rich text box. The following is what I have carried out:

VB
<dllimport("user32")> _
    Private Shared Function HideCaret(ByVal hwnd As IntPtr) As Integer

    End Function

 Private Sub rtbReport_GotFocus(sender As Object, e As System.EventArgs) Handles rtbReport.GotFocus
        HideCaret(rtbReport.Handle)
    End Sub

But I am afraid the above does not work.

Any ideas would greatly be appreciated it.

[edit] code tags added [/edit]
Posted
Updated 25-May-12 9:59am
v2
Comments
Sergey Alexandrovich Kryukov 25-May-12 11:54am    
Why hiding a caret? Even if the document is read-only, it can be used to select some text and copy it to the clipboard. Removing it would hurt the user's right for information.
--SA
Member1978 26-May-12 12:50pm    
Hello Sakryukov,
Many thanks for your reply. The main objective here is to state what the application is doing and has already implemented. The customer dislike the blinking cursor and as a result one must do their best to deliver. I implemented this action many years back in VB6 so I assumed the implementation would be just as easy in VB.NET.
Gregory Gadow 25-May-12 16:50pm    
Are you trying to hide the cursor (the mouse pointer) or the caret (the blinking bar that indicates the current position within the text)? And why?

You cannot hide the cursor, although you can use the control's Cursor property to change the cursor that appears when the user hovers over the control. There really is no effective way to hide the caret, but you can use the control's ReadOnly property to make it... well, read only. That means the user cannot edit what is there.
Sergey Alexandrovich Kryukov 28-May-12 19:44pm    
Agree. I suggested the alternative which works very well, but it might depend on the application requirements. I think it might be interesting, please see.
--SA

I'm sorry if my advice does not address the problem, but you could think of a very good alternative to using RichTextBox. There are a couple of very good components on CodeProject offering rendering of HTML instead. Please see:

For Forms:
A Professional HTML Renderer You Will Use[^].

For WPF:
WPF HTML Supported TextBlock[^].

—SA
 
Share this answer
 
I am afraid by implementing the following does not hide the rich text box control caret:

<dllimport("user32")> _
Private Shared Function HideCaret(ByVal hwnd As IntPtr) As Integer

End Function

‘Your rich text box=rtbReport
Private Sub rtbReport_GotFocus(sender As Object, e As System.EventArgs) Handles rtbReport.GotFocus
HideCaret(rtbReport.Handle)
End Sub

Solution:
The method which eventually worked for me is to call
rtbReport.TabStop = False Within the form load event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900