none
Transfer Image from One picturebox in form1 into form 2

    Question

  • I have code here which successfully transfers the picturebox1 image into the second picturebox but I want it to transfer across windows form. Anybody know how? Here is the code done thus far. 

    Public Class Form1
        Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
            PictureBox1.DoDragDrop(PictureBox1.Image, DragDropEffects.Copy)
    
            Form2.Show()
        End Sub
    
        Private Sub PictureBox2_DragDrop(sender As Object, e As DragEventArgs) Handles PictureBox2.DragDrop
            PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)
    
        End Sub
    
        Private Sub PictureBox2_DragEnter(sender As Object, e As DragEventArgs) Handles PictureBox2.DragEnter
    
            If e.Data.GetDataPresent(DataFormats.Bitmap) Then 'If the thing you are copying is text
                e.Effect = DragDropEffects.Copy 'Copy cursor
            Else
                e.Effect = DragDropEffects.None 'If not text leave cursor as is
            End If
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox2.AllowDrop = True
        End Sub
    End Class
    

    Public Class Form2
        Private Sub Form2_DragEnter(sender As Object, e As DragEventArgs) Handles Me.DragEnter
            If e.Data.GetDataPresent(DataFormats.Bitmap) Then 'If the thing you are copying is text
                e.Effect = DragDropEffects.Copy 'Copy cursor
            Else
                e.Effect = DragDropEffects.None 'If not text leave cursor as is
            End If
        End Sub
    
        Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            PictureBox3.AllowDrop = True
    
        End Sub
    
        Private Sub PictureBox2_DragDrop(sender As Object, e As DragEventArgs) Handles PictureBox3.DragDrop
            PictureBox3.Image = e.Data.GetData(DataFormats.Bitmap)
        End Sub
    End Class


    WRA

    Sunday, March 19, 2017 2:06 PM

Answers

  • I think that you should copy PictureBox2_DragEnter to Form2 and adjust it for PictureBox3. Currently you have DragEnter for the form, which is not needed if you drop to picture box only.

    • Marked as answer by Waliur Rahman Monday, March 20, 2017 1:42 PM
    Sunday, March 19, 2017 7:44 PM

All replies

  • I think that you should copy PictureBox2_DragEnter to Form2 and adjust it for PictureBox3. Currently you have DragEnter for the form, which is not needed if you drop to picture box only.

    • Marked as answer by Waliur Rahman Monday, March 20, 2017 1:42 PM
    Sunday, March 19, 2017 7:44 PM
  • Thanks for the solution I was able to drag the image from one form into the next :)

    WRA

    Monday, March 20, 2017 1:42 PM