RichtextBox Drag Drop Issue

Posted 20 August 2013 - 04:14 PM

Hello, I have written code to allow text and files to be dragged to a richtextbox. I don't want the files to show as I add them to a list and display elsewhere on the form. So I check what type of data it is and it all works fine.

What I am having a problem with is drag text around within the Richtextbox field. When you select text and drag it, the cursor turns into a red X and the dragEndter and DragDrop handlers never fire. So I can't drag anything OUT of the richtextbox. It is not a real serious thing, but it is annoying when trying to drag text around the richtextbox.

My Richtext DragEnter handler

If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.Copy
End If
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Move
End If

My DragDrop handler

For Each dFormat In e.Data.GetFormats()
If dFormat = DataFormats.Text Then
Dim i As Int16
Dim s As String
' Get start position to drop the text.
i = TextBoxMessage.Selectionstart
s = TextBoxMessage.Text.Substring(i)
TextBoxMessage.Text = TextBoxMessage.Text.Substring(0, i)
' Drop the text on to the RichTextBox.
TextBoxMessage.Text = TextBoxMessage.Text + _
e.Data.GetData(DataFormats.Text).ToString()
TextBoxMessage.Text = TextBoxMessage.Text + s
End If
If dFormat = DataFormats.FileDrop Then
Dim files() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
For Each file In files
Dim newAttachmenta As New attachments
newAttachmenta.filename = System.IO.Path.GetFileName(file)
newAttachmenta.fullfilename = file
attachList.Add(newAttachmenta)
AttachmentList.Items.Add(newAttachmenta.filename)
Next
If SplitContainer2.Panel2Collapsed Then SplitContainer2.Panel2Collapsed = False
End If
Next