Bonjour

je suis en train d'élaborer un petit jeu qui fonctionne avec des images a glisser deposer dans la bonne case.

je voudrais connaitre le nom de l'image déposée dans la picturebox pour comptabiliser les bonnes réponses.

voici mon code (simplifié à 2 picturebox source et 2 picturebox cible)

le drag and drop image marche exactement comme je le souhaite mais je ne parvient pas a trouver comment afficher dans un label juste au dessus de la picturebox cible le nom de l'image dropée.

merci de votre aide

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        picDropTarget1.AllowDrop = True
        picDropTarget2.AllowDrop = True
 
        picDragSource1.Tag = "selectionner_le_chocolat.png"
        picDragSource2.Tag = "afficher_prix_a_payer.png"
 
 
 
    End Sub
 
    Private nomdelimage As String
    Private MouseIsDown As Boolean = False 'flag
 
    ' Start the drag.
    Private Sub picDragSource_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDragSource1.MouseDown, picDragSource2.MouseDown ', picDragSource3.MouseDown, picDragSource4.MouseDown, picDragSource5.MouseDown, picDragSource6.MouseDown, picDragSource7.MouseDown, picDragSource8.MouseDown, picDragSource9.MouseDown, picDragSource10.MouseDown, picDragSource11.MouseDown
 
        ' Start the drag if it's the left mouse button.
 
        Dim tagimage As String = CStr(CType(sender, System.Windows.Forms.PictureBox).Tag)
 
        If (e.Button = MouseButtons.Left) Then
 
            picDragSource1.DoDragDrop(DirectCast(sender, PictureBox).Image, DragDropEffects.Copy)
            picDragSource1.DoDragDrop(picDragSource1.Name, DragDropEffects.Copy) 'Lorsque j'appuis je recuperer le nom de ma picturebox
            picDragSource2.DoDragDrop(DirectCast(sender, PictureBox).Image, DragDropEffects.Copy)
            picDragSource2.DoDragDrop(picDragSource2.Name, DragDropEffects.Copy) 'Lorsque j'appuis je recuperer le nom de ma picturebox
 
 
 
        End If
    End Sub
 
 
    ' Allow a copy of an image.
    Private Sub picDropTarget1_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picDropTarget1.DragEnter
        ' See if this is a copy and the data includes an image.
 
        If (e.Data.GetDataPresent(DataFormats.Bitmap) AndAlso (e.AllowedEffect And DragDropEffects.Copy) <> 0) Then
            ' Allow this.
            e.Effect = DragDropEffects.Copy
 
 
 
        Else
            ' Don't allow any other drop.
            e.Effect = DragDropEffects.None
        End If
    End Sub
    ' Accept the drop.
    Private Sub picDropTarget1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picDropTarget1.DragDrop
        Dim bm As Bitmap = DirectCast(e.Data.GetData(DataFormats.Bitmap, True), Bitmap)
 
        picDropTarget1.Image = bm
 
    End Sub
    ' Allow a copy of an image.
    Private Sub picDropTarget2_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picDropTarget2.DragEnter
        ' See if this is a copy and the data includes an image.
 
        If (e.Data.GetDataPresent(DataFormats.Bitmap) AndAlso (e.AllowedEffect And DragDropEffects.Copy) <> 0) Then
            ' Allow this.
            e.Effect = DragDropEffects.Copy
 
 
        Else
            ' Don't allow any other drop.
            e.Effect = DragDropEffects.None
        End If
    End Sub
    ' Accept the drop.
    Private Sub picDropTarget_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles picDropTarget2.DragDrop
        Dim bm As Bitmap = DirectCast(e.Data.GetData(DataFormats.Bitmap, True), Bitmap)
 
        picDropTarget2.Image = bm
 
 
    End Sub
 
    'bouton d'effacement
 
 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'PictureBox1.Image = Nothing
        picDropTarget1.Image = Nothing
 
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'PictureBox2.Image = Nothing
        picDropTarget2.Image = Nothing
        rep22.Text = ""
    End Sub
 
 
    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
 
    End Sub
End Class