Solved

Drag and drop from external source

Posted on 2006-07-16
2
226 Views
Last Modified: 2010-04-23
Hi Experts,

I would like to be able to drag and drop a file onto my application from the windows explorer and open that file in a rich text box using the RichTextBox.loadfile command. On the drag drop event for my form i need to know the path for the dragged file. Also if the file is a shortcut i would like to grab the target path.

How can i achieve this?

Cheers,

Tom
0
Comment
Question by:TommyTwoPints
2 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 500 total points
ID: 17116964
Hello Tom,

  Here's a quick example that will enable the dragEnter and DragDrop events to work with RichTextBox, so you can drag any "RTF" file and drop it in your application

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       RichTextBox1.AllowDrop = True
        AddHandler Me.RichTextBox1.DragEnter, New System.Windows.Forms.DragEventHandler(AddressOf Me.RichTextBox1_DragEnter)
        AddHandler Me.RichTextBox1.DragDrop, New System.Windows.Forms.DragEventHandler(AddressOf Me.RichTextBox1_DragDrop)
    End Sub

    Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
        If CType(e, DragEventArgs).Data.GetDataPresent(DataFormats.FileDrop) Then
            CType(e, DragEventArgs).Effect = DragDropEffects.All
        Else
            CType(e, DragEventArgs).Effect = DragDropEffects.None
        End If
    End Sub

    Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs)
        Dim s As String() = e.Data.GetData(DataFormats.FileDrop)
        RichTextBox1.LoadFile(s(0))
    End Sub

HTH


Regards,
Mohammed Nasman
0
 
LVL 3

Author Comment

by:TommyTwoPints
ID: 17116990
Thats excellent, thanks!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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