Drag n Drop Issue

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
4 posts Page 1 of 1
Contributors
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Drag n Drop Issue
hungryhounduk
Hey Coders

I have a problem with Drag n Drop Images to a RichTextBox
I am using VB 2010 Pro

It works fine when i am creating the app and run it within VB, But when I build it and run it on the desktop the Drag n Drop does not work..

This is the code below I am using for Drag n Drop

Imports
Code: Select all
Imports System.Reflection
Imports System.IO

Form Load
Code: Select all
 RichTextBox1.AllowDrop = True
Code: Select all
Private Sub RichTextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragDrop
        Dim files As Array = e.Data.GetData(DataFormats.FileDrop)
        MsgBox(files.Length & " Image Added")
        Dim bmpFormat As DataFormats.Format = DataFormats.GetFormat(DataFormats.Bitmap)
        For i As Integer = 0 To files.Length - 1
            Dim bmp As Bitmap = Bitmap.FromFile(files(i))
            Clipboard.SetData(DataFormats.Bitmap, bmp)
            bmp.Dispose()

            RichTextBox1.Paste(bmpFormat)
        Next
        Clipboard.Clear()
    End Sub
Code: Select all
Private Sub RichTextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles RichTextBox1.DragEnter
        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub



Cheers

Chris
Image
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Re: Drag n Drop Issue
CodenStuff
Your code looks fine and it works for me.

Make sure you run the application as administrator and see if that works.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Re: Drag n Drop Issue
hungryhounduk
Hey Cody
I am running it as admin, I tried it in VB 2013 Community Edition and that throws up errors for .Net Framework. But I am sure I have the .Net frameworks installed, so I dont know what the issue is?

Chris
Image
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Re: Drag n Drop Issue
CodenStuff
Check if you have any system/windows updates that need downloading and installing.

I'm not sure what could be wrong :?

Try this one that I made using your code, I've tested it and it works fine for me.
WindowsApplication24.zip
You do not have the required permissions to view the files attached to this post.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
4 posts Page 1 of 1
Return to “Coding Help & Support”