Solved

VB.net drag and drop into RichTextBox

Posted on 2012-04-09
2
1,252 Views
Last Modified: 2012-04-09
Hi. I was given code to drag and drop from a ListBox into a TextBox asnd it worked well.
I also need to be able to drop into a RichTextBox. The following code doesn't achieve that.
I set AllowDrop = True in the form load event.


    Private Sub ListBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
        ' Drag and Drop STEP 1
        If e.Button = Windows.Forms.MouseButtons.Left AndAlso Me.ListBox1.SelectedItem IsNot Nothing Then
            Me.ListBox1.DoDragDrop(Me.ListBox1.SelectedItem.ToString(), DragDropEffects.Copy)
        End If

    End Sub

    Private Sub RichTextBox1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        ' Drag and Drop STEP 2
        If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.StringFormat) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub


    Private Sub RichTextBox1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
        ' Drag and Drop STEP 3
        If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.StringFormat) Then
            Me.RichTextBox1.Text = e.Data.GetData(System.Windows.Forms.DataFormats.StringFormat).ToString()
        End If
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
DragEnter doesn't seem to function in the same way for RTB as it does for TB. I switched to DragOver, and it appears to work.

Private Sub RichTextBox1_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragOver
    ' Drag and Drop STEP 2
    If e.Data.GetDataPresent(System.Windows.Forms.DataFormats.StringFormat) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
Comment Utility
Thanks very much
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now