Solved

Drag and drop from external source

Posted on 2006-07-16
2
228 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

839 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