I have a RichTextBox which I would like to treat certain text formats as single blocks which are distinguishable by color. For instance, in the sentence below 'jump' would be treated as a single block. [This is highly simplified to demonstrate my problem.]
'The dog jumped over the cat"
When the user doubleclicks anywhere in 'jump' I determine that the color is red and select all red items left to right.
The problem is that the user sees two selections. 1. original selection: 'jumped ' 2. the programs selection: 'jump'. I want to cancel the original DoubleClick selection so there are not two selections. T thought this would be simialar to canceling the keypress event using
e.Handled = True
I cannot find anything to cancel MouseEventArgs. I believe the answer may be in catching and canceling the actual windows message. I, however, am not sure how to do this.
Any help would be appreciated.

How do you cancel MouseDoubleClick?
Stephen M. Berube
What you need to do is to add a message filter to the form and cancel any double click messages that are going to the form and perform your own handling. Create a new winforms project, add a richtextbox to it and change code inside it to be
Public
Class Form1Implements IMessageFilter
Private Sub RichTextBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.DoubleClick
RichTextBox1.Text += "Standard" 'Gets printed if no message filter
End Sub
Private Sub RichTextBox1_SpecialDoubleClick()
RichTextBox1.Text += "Special" 'Gets printed from PreFilterMessage for double click in a rtb
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Application.AddMessageFilter(Me) 'Add the filter, skip this to test standard event handler
End Sub
Private Const WM_MBUTTONDBLCLK As Integer = &H203 'Double click with left mouse button
Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Select Case (m.Msg)
Case WM_MBUTTONDBLCLK
Dim ctrl As Control = Control.FromHandle(m.HWnd) ' Find the control associated with the window handle
If Not ctrl Is Nothing AndAlso True = ctrl.Equals(RichTextBox1) Then
RichTextBox1_SpecialDoubleClick()
Return True 'Cancels the message and default event handler will never run
End If
End Select
Return False
End Function
End Class