[RESOLVED] Picturebox help
Hi, i've placed the images I want to use in the projects resource file (any old image to test), and i've loaded them into the picture boxes when the application loads.
I use drag & drop and can change the picture from one box to the other, and basicaly swap them around. One problem.... I can't figure out what picture is in which box after i've moved them.
Is there any way to somhow receive or return the name of the picture currently in a picturebox (i.e the name of the image in the resource file)
Thanks.
Re: [RESOLVED] Picturebox help
here's a solution:
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Item1.Image = My.Resources.[resourceName1]
Item1.Tag = "[resourceName1]"
Item2.Image = My.Resources.[resourceName2]
Item2.Tag = "[resourceName2]"
MainItem.Image = My.Resources.[resourceName3]
MainItem.Tag = "[resourceName3]"
Label1.Text = "Item1.Tag = " & Item1.Tag
Label2.Text = "Item2.Tag = " & Item2.Tag
Label3.Text = "MainItem.Tag = " & MainItem.Tag
Item1.AllowDrop = True
Item2.AllowDrop = True
MainItem.AllowDrop = True
End Sub
Dim source As PictureBox
Private Sub Items_Mousedown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Item1.MouseDown, Item2.MouseDown
source = DirectCast(sender, PictureBox)
'Source PictureBox
If e.Button = MouseButtons.Left Then
source.DoDragDrop(source.Image, DragDropEffects.Move)
End If
End Sub
Private Sub MainItem_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MainItem.DragDrop
'Set the image to be the dragged image.
If (e.Data.GetDataPresent(DataFormats.Bitmap)) Then
TempImage.Image = MainItem.Image
TempImage.Tag = MainItem.Tag
MainItem.Image = CType((e.Data.GetData(DataFormats.Bitmap)), Bitmap)
MainItem.Tag = source.Tag
source.Image = TempImage.Image
source.Tag = TempImage.Tag
Label1.Text = "Item1.Tag = " & Item1.Tag
Label2.Text = "Item2.Tag = " & Item2.Tag
Label3.Text = "MainItem.Tag = " & MainItem.Tag
End If
End Sub
Private Sub MainItem_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MainItem.DragOver
'Target PictureBox
'Drag Drop Effects
If e.Data.GetDataPresent(DataFormats.Bitmap) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
End Class