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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)