Bonsoir,
Je créer actuellement une application qui sera totalement configurable par l'utilisateur final, pour ce faire j'utilise une boite à outils qui contient 4 éléments, tout ces éléments seront des objets dérivés de picturebox, des controls utilisateurs qui hérite de la class picturebox.
Lors d'un Drag & Drop de l'un de ces éléments sur ma Form principal, j'aimerais vérifier quel élément est droppé sur la form.

J'utilise aujourd'hui dans la boite à outils :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
    Private Sub ToolBoxLamp_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ToolBoxLamp.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.ToolBoxLamp.DoDragDrop(ToolBoxLamp.Image, DragDropEffects.Copy)
        End If
    End Sub
 
    Private Sub ToolBoxSwitch_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles ToolBoxSwitch.MouseDown
        If e.Button = Windows.Forms.MouseButtons.Left Then
            Me.ToolBoxSwitch.DoDragDrop(ToolBoxSwitch.Image, DragDropEffects.Copy)
        End If
    End Sub
Et le code suivant dans la Form principale :

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
    Private Sub Panel1_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles Panel1.DragDrop
        If e.Data.GetDataPresent(DataFormats.Bitmap) Then
 
            If e.Data.GetData(DataFormats.Bitmap).ToString = My.Resources.light.ToString Then
                TextBox1.Text = e.Data.GetData(DataFormats.Bitmap).ToString()
                Dim Pb As New HmiObjButton
                Pb.Image = e.Data.GetData(DataFormats.Bitmap)
                Pb.Name = "Pb" & GetObjQuantityInConfigurationFile(My.Settings.ConfigurationFilePath, "HmiObject")
                Pb.Size = New Point(50, 50)
                Pb.SizeMode = PictureBoxSizeMode.Zoom
                Pb.Location = New Point(Panel1.PointToClient(Cursor.Position).X - (Pb.Width / 2), Panel1.PointToClient(Cursor.Position).Y - (Pb.Height / 2))
                Pb.EventValue = 1
                Pb.Tag = TextBox1.Text
                Pb.BackColor = Color.Transparent
                AddHandler Pb.Click, AddressOf PbClick
                AddHandler Pb.MouseDown, AddressOf PbMouseDown
                AddHandler Pb.MouseMove, AddressOf PbMouseMove
                AddHandler Pb.MouseUp, AddressOf PbMouseUp
                Me.Panel1.Controls.Add(Pb)
                AddElementInConfigurationFile(My.Settings.ConfigurationFilePath, Pb.Name, New Size(50, 50), New Point(Panel1.PointToClient(Cursor.Position).X - (Pb.Width / 2), Panel1.PointToClient(Cursor.Position).Y - (Pb.Height / 2)))
            ElseIf e.Data.GetData(DataFormats.Bitmap).ToString = My.Resources.switch.ToString Then
                Dim Pb As New HmiObjButton
                Pb.Image = e.Data.GetData(DataFormats.Bitmap)
                Pb.Name = "Pb" & GetObjQuantityInConfigurationFile(My.Settings.ConfigurationFilePath, "HmiObject")
                Pb.Size = New Point(50, 50)
                Pb.SizeMode = PictureBoxSizeMode.Zoom
                Pb.Location = New Point(Panel1.PointToClient(Cursor.Position).X - (Pb.Width / 2), Panel1.PointToClient(Cursor.Position).Y - (Pb.Height / 2))
                Pb.EventValue = 1
                Pb.Tag = TextBox1.Text
                Pb.BackColor = Color.Transparent
                AddHandler Pb.Click, AddressOf PbClick
                AddHandler Pb.MouseDown, AddressOf PbMouseDown
                AddHandler Pb.MouseMove, AddressOf PbMouseMove
                AddHandler Pb.MouseUp, AddressOf PbMouseUp
                Me.Panel1.Controls.Add(Pb)
                AddElementInConfigurationFile(My.Settings.ConfigurationFilePath, Pb.Name, New Size(50, 50), New Point(Panel1.PointToClient(Cursor.Position).X - (Pb.Width / 2), Panel1.PointToClient(Cursor.Position).Y - (Pb.Height / 2)))
            End If
        End If
    End Sub
Je n'arrive pas à récupérer soit le nom de l'image source, soit le type ou le nom de l'objet source.

Si vous avez quelques tuyaux pour m'aider, je vous remercie par avance.