1 Replies - 2243 Views - Last Post: 21 August 2013 - 08:36 PM Rate Topic: -----

#1 vbnet9  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 366
  • Joined: 26-May 09

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 + _
                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


                If SplitContainer2.Panel2Collapsed Then SplitContainer2.Panel2Collapsed = False

            End If


Is This A Good Question/Topic? 0
  • +

Replies To: RichtextBox Drag Drop Issue

#2 vbnet9  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 366
  • Joined: 26-May 09

Re: RichtextBox Drag Drop Issue

Posted 21 August 2013 - 08:36 PM

Does any one have an idea?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1