Solved

Drag and drop from external source

Posted on 2006-07-16
2
224 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:
mnasman 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 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

19 Experts available now in Live!

Get 1:1 Help Now