Solved

VB.net drag and drop into RichTextBox

Posted on 2012-04-09
2
1,290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 37823069
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
ID: 37823085
Thanks very much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net - Get ColumnNames of SQL Table 4 19
VB.net and sql server 4 54
vb.net and creating a class 5 29
How to share My.Settings in multiple application instances ? 7 48
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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