Search code examples
.netvb.netwinformsvisual-studio-2017oledragdrop

Implementing Drop on Picturebox on Form


I seem unable to make it so that I can drop a file from the desktop to a PictureBox on a Form.

I went through all the docs I could find, but anyways the cursor always stays a stop sign.

What I did was:

Set the Form's "AllowDrop" to True.

In my code I have

Private Sub pb0A_DragOver(sender As Object, e As DragEventArgs) Handles pb0A.DragOver
    e.Effect = DragDropEffects.Copy
End Sub

Private Sub pb0A_DragEnter(sender As Object, e As DragEventArgs) Handles pb0A.DragEnter
    e.Effect = DragDropEffects.Copy
End Sub

In the docs I read that I should set the PictureBox'es property "AllowDrop" to True, but using Framework 4.5.2, I don't have this property.

I'm not running VS as an admin.

What else might be the problem here?


Solution

  • For some reason Microsoft has intentionally hidden the PictureBox.AllowDrop property. It isn't visible in the designer nor listed by IntelliSense, however it does exist so you can still set it through code:

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PictureBox1.AllowDrop = True
    End Sub