Click here to Skip to main content
13,299,298 members (64,041 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
I'm trying to drag and drop a particular picturebox but I can't get what I want. I want the image seem like it is being hold during mousemove/mousedown like a normal drag and drop but it a "box with +" is the only thing appears during the said events. Please help me. These are my codes:

 

Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop
    Dim bm As Bitmap = _
       DirectCast(e.Data.GetData(DataFormats.Bitmap, True),  _
       Bitmap)
 

    If PictureBox3.Tag = PictureBox1.Tag And PictureBox4.Tag = PictureBox1.Tag Then
        PictureBox2.Image = bm
    Else
        PictureBox2.Image = OldImage2
        PictureBox1.Image = OldImage1
    End If
 
End Sub
Private Sub PictureBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragEnter
    If (e.Data.GetDataPresent(DataFormats.Bitmap) AndAlso _
    (e.AllowedEffect And DragDropEffects.Copy) <> 0) _
 Then
        ' Allow this.
        e.Effect = DragDropEffects.Copy
 
        ' Save the current image.
        OldImage1 = PictureBox1.Image
        OldImage2 = PictureBox2.Image
 
        PictureBox2.Image = OldImage1
        PictureBox1.Image = OldImage2
 

    Else
        ' Don't allow any other drop.
        e.Effect = DragDropEffects.None
    End If
End Sub
Private Sub PictureBox2_DragLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox2.DragLeave
    ' Restore the saved image.
    PictureBox2.Image = OldImage2
    PictureBox1.Image = OldImage1
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
 
 
    ' Start the drag if it's the right mouse button.
    If (e.Button = MouseButtons.Left) Then
        Dim source As PictureBox = DirectCast(sender,  _
            PictureBox)
        PictureBox1.DoDragDrop(source.Image, _
            DragDropEffects.Copy)
    End If
 
End Sub
 

Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
    Dim bm As Bitmap = _
       DirectCast(e.Data.GetData(DataFormats.Bitmap, True),  _
       Bitmap)
 

    If PictureBox9.Tag = PictureBox1.Tag And PictureBox17.Tag = PictureBox1.Tag Then
        PictureBox1.Image = bm
    Else
        PictureBox1.Image = OldImage2
        PictureBox2.Image = OldImage1
    End If
 
    'If PictureBox3.Tag = PictureBox1.Tag And PictureBox4.Tag = PictureBox1.Tag Then
    'Else
    '    MsgBox("NOT THE SAME")
    'End If
 
End Sub
Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
    If (e.Data.GetDataPresent(DataFormats.Bitmap) AndAlso _
    (e.AllowedEffect And DragDropEffects.Copy) <> 0) _
 Then
        ' Allow this.
        e.Effect = DragDropEffects.Copy
 
        ' Save the current image.
        OldImage2 = PictureBox1.Image
        OldImage1 = PictureBox2.Image
 
        PictureBox1.Image = OldImage1
        PictureBox2.Image = OldImage2
 

    Else
        ' Don't allow any other drop.
        e.Effect = DragDropEffects.None
    End If
End Sub
Private Sub PictureBox1_DragLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.DragLeave
    ' Restore the saved image.
    PictureBox2.Image = OldImage1
    PictureBox1.Image = OldImage2
End Sub
Private Sub PictureBox2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseDown
 

 
    ' Start the drag if it's the right mouse button.
    If (e.Button = MouseButtons.Left) Then
        Dim source As PictureBox = DirectCast(sender,  _
            PictureBox)
        PictureBox2.DoDragDrop(source.Image, _
            DragDropEffects.Copy)
    End If
End Sub
 


Thanks.
Posted 26-Oct-14 5:30am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 26 Oct 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100