How to hide the caret in a RichTextBox?

后端 未结 9 1750
[愿得一人]
[愿得一人] 2020-12-31 15:10

Just like the title: I\'ve searched the web for an answer, but i was not able to find a way to hide the caret of a RichTextBox in VB.NET.

I\'ve tried to set the Rich

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 15:46

    Here I have a Rich Text control named txtMessage, it's events are handled to hide caret on events that would show it.

    
    Private Shared Function HideCaret(ByVal hWnd As IntPtr) As Boolean
    End Function
    
    Public Sub New()
        txtMessage.ReadOnly = True
        txtMessage.TabStop = False
    End Sub
    
    Private Sub txtMessage_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtMessage.KeyUp
        HideCaret(txtMessage.Handle)
    End Sub
    
    Private Sub txtMessage_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtMessage.MouseDown
        HideCaret(txtMessage.Handle)
    End Sub
    
    Private Sub txtMessage_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtMessage.SelectionChanged
        HideCaret(txtMessage.Handle)
    End Sub
    

提交回复
热议问题