picturebox

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
picturebox [solved]

hi to everyone..good day
i have a form w/ corresponding pictureboxes: picturebox1 and picturebox2
in picturebox1 there is an image
what i want is the user can drag the image to picturebox2 and drop...vice versa


thanks and more power...:cool:
im sorry..
it shouldn't be here...
i forgot....
 
Last edited:
Hi try this,

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox2.AllowDrop =
True

End Sub

Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

DoDragDrop(PictureBox1.Image, DragDropEffects.Copy)

End Sub

Private Sub PictureBox2_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragOver

If (e.Data.GetDataPresent(DataFormats.Bitmap)) Then

e.Effect = DragDropEffects.Copy

Else

e.Effect = DragDropEffects.None

End If

End Sub

Private Sub PictureBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox2.DragDrop

PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap)

End Sub

 
already solved...

hi to every one..
i already got it..
heres the code:
VB.NET:
 Const c As Byte = 8
 
 	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 		picleft.AllowDrop = True
 		picright.AllowDrop = True
 	End Sub
 
 'in the mousedown event
 	Private Sub md(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picleft.MouseDown, picright.MouseDown
 		Dim pic As PictureBox = CType(sender, PictureBox)
 		If Not pic.Image Is Nothing Then
 		    pic.DoDragDrop(pic.Image, DragDropEffects.Copy Or DragDropEffects.Move)
 		End If
 	End Sub
 
 'in the dragenter events
 	Private Sub de(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picleft.DragEnter, picright.DragEnter
 		If e.Data.GetDataPresent(DataFormats.Bitmap) Then
 			If e.KeyState = c Then
 				e.Effect = DragDropEffects.Copy
 			Else
 				e.Effect = DragDropEffects.Move
 			End If
 		Else
 			e.Effect = DragDropEffects.None
 		End If
 	End Sub
 
 'in the dragdrop events
 	Private Sub dd(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picleft.DragDrop, picright.DragDrop
 		Dim pic As PictureBox = CType(sender, PictureBox)
 		pic.Image = e.Data.GetData(DataFormats.Bitmap)
 		If e.KeyState <> c Then
 			If pic.Name = "picleft" Then
 				picright.Image = Nothing
 			Else
 				picleft.Image = Nothing
 			End If
 		End If
 	End Sub
 
Back
Top