В моем usercontrol я хочу, чтобы пользователь не выбирал текст, я хочу сказать, что хочу отменить (игнорировать) все события мыши, я переопределил важные события, но, похоже, ничего не делает, потому что я все еще могу выбрать текст на элементе управления.Игнорирование выбора текста в унаследованном RichTextbox?
PS: Я не могу отключить элемент управления для предотвращения выбора, я хочу отключить выбор.
Public Class RichTextLabel : Inherits RichTextBox
Private Declare Function HideCaret Lib "user32" (ByVal hwnd As IntPtr) As Integer
Public Sub New()
Me.TabStop = False
Me.Cursor = Cursors.Default
Me.Size = New Point(200, 20)
Me.ReadOnly = True
Me.BorderStyle = BorderStyle.None
Me.ScrollBars = RichTextBoxScrollBars.None
End Sub
Public Sub Add_Colored_Text(ByVal text As String, _
ByVal color As Color, _
Optional ByVal font As Font = Nothing)
Dim index As Int32 = Me.TextLength
Me.AppendText(text)
Me.SelectionStart = index
Me.SelectionLength = Me.TextLength - index
Me.SelectionColor = color
If font IsNot Nothing Then Me.SelectionFont = font
Me.SelectionLength = 0
End Sub
#Region " Overrided Events "
Protected Overrides Sub OnClick(ByVal e As EventArgs)
HideCaret(Me.Handle)
Return
End Sub
Protected Overrides Sub OnSelectionChanged(ByVal e As EventArgs)
HideCaret(Me.Handle)
Return
End Sub
Protected Overrides Sub OnMouseClick(ByVal e As MouseEventArgs)
HideCaret(Me.Handle)
' MyBase.OnClick(e)
Return
End Sub
Protected Overrides Sub OnMouseDoubleClick(ByVal e As MouseEventArgs)
HideCaret(Me.Handle)
Return
End Sub
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
HideCaret(Me.Handle)
Return
End Sub
Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
HideCaret(Me.Handle)
Return
End Sub
#End Region
#Region " Handled Events "
Private Sub On_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Me.MouseHover
HideCaret(Me.Handle)
End Sub
Private Sub On_TextChanged(sender As Object, e As EventArgs) Handles Me.TextChanged
HideCaret(Me.Handle)
End Sub
#End Region
End Class
Почему вы не можете отключить управление? Это только потому, что текст становится серым? – tehDorf