Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Drag and drop from external source

Posted on 2006-07-16
2
Medium Priority
?
232 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
[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 22

Accepted Solution

by:
Mohammed Nasman earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

722 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