Bonsoir,

En relisant les FAQ récentes j'ai compris qu'il fallait déjouer cette impossibilité d'indexer en utilisant Tag. J'ai affecté Tag de chaque image avec les n°1 à 64 (64 cases d'un échiquier) => OK ça marche voir le code suivant

A noter que les mouvement de la souris utilise mousedown et mousemouve ainsi que dragdrop sur le picturebox final.
GiveFeedback est utilisé pour adapter l'image bmp d'une pièce d'échec appelé RN au curseur de la souris pour voir son mouvement.

Le code :

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
Public Class Form1
 
    Dim MouseIsDown As Boolean = False
    Dim CursorImage As Image
    Dim isDragging As Boolean = False
    Dim CurrentX As Integer, CurrentY As Integer
    Dim CaseEch(64) As ButtonBase
    Dim aaa As String
    Dim Pieces As String
    Dim LocationX(64) As Integer
    Dim LocationY(64) As Integer
 
 
    Private Property mypic As Point
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PictureBox1.AllowDrop = True
        PictureBox2.AllowDrop = True
        PictureBox3.AllowDrop = True
        PictureBox4.AllowDrop = True
        PictureBox5.AllowDrop = True
        PictureBox6.AllowDrop = True
        PictureBox7.AllowDrop = True
        PictureBox8.AllowDrop = True
        PictureBox9.AllowDrop = True
 
 
 Public Sub RB_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RB.MouseDown
        MouseIsDown = True
    End Sub
 
 
    Public Sub RB_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RB.MouseMove
        If MouseIsDown Then
            If RB.Image Is Nothing Then Exit Sub
            RB.DoDragDrop(RB.Image, DragDropEffects.Move)
        Else
            MouseIsDown = False
        End If
    End Sub
 
 
    Public Sub RB_GiveFeedback(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles RB.GiveFeedback
        e.UseDefaultCursors = False
        Dim myPic As New Bitmap(CType(sender, PictureBox).Image)
        CursorImage = myPic.GetThumbnailImage(32, 32, Nothing, IntPtr.Zero)
        Cursor.Current = New Cursor(CType(CursorImage, System.Drawing.Bitmap).GetHicon())
        Pieces = "RB"
    End Sub
 
 
    Public Sub RN_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RN.MouseDown
        MouseIsDown = True
    End Sub
 
 
    Public Sub RN_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles RN.MouseMove
        If MouseIsDown Then
            If RN.Image Is Nothing Then Exit Sub
            RN.DoDragDrop(RN.Image, DragDropEffects.Move)
        Else
            MouseIsDown = False
        End If
    End Sub
 
 
    Public Sub RN_GiveFeedback(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles RN.GiveFeedback
        e.UseDefaultCursors = False
        Dim myPic As New Bitmap(CType(sender, PictureBox).Image)
        CursorImage = myPic.GetThumbnailImage(32, 32, Nothing, IntPtr.Zero)
        Cursor.Current = New Cursor(CType(CursorImage, System.Drawing.Bitmap).GetHicon())
        Pieces = "RN"
    End Sub
 
 
 Public Sub PictureBox_DragDrop(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop, PictureBox2.DragDrop, PictureBox3.DragDrop, PictureBox4.DragDrop, PictureBox5.DragDrop, PictureBox6.DragDrop, PictureBox7.DragDrop, PictureBox8.DragDrop
 
        Dim clicked As PictureBox = CType(sender, PictureBox)
        Tag = sender.tag
 
        If Tag = 1 Then PictureBox1.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox1.Location.X : LocationY(Tag) = PictureBox1.Location.Y
        If Tag = 2 Then PictureBox2.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox2.Location.X : LocationY(Tag) = PictureBox2.Location.Y
        If Tag = 3 Then PictureBox3.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox3.Location.X : LocationY(Tag) = PictureBox3.Location.Y
        If Tag = 4 Then PictureBox4.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox4.Location.X : LocationY(Tag) = PictureBox4.Location.Y
        If Tag = 5 Then PictureBox5.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox5.Location.X : LocationY(Tag) = PictureBox5.Location.Y
        If Tag = 6 Then PictureBox6.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox6.Location.X : LocationY(Tag) = PictureBox6.Location.Y
        If Tag = 7 Then PictureBox7.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox7.Location.X : LocationY(Tag) = PictureBox7.Location.Y
        If Tag = 8 Then PictureBox8.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox8.Location.X : LocationY(Tag) = PictureBox8.Location.Y
 
 
 
        TextBox1.Text = "Tag: " + Tag.ToString + "    Piece: " + Pieces + "              Location X,Y :  " + LocationX(Tag).ToString + " , " + LocationY(Tag).ToString
    End Sub
 
 
End Class
Ce code est donné pour les 8 premières cases dans le sub PictureBox_DragDrop, il n'est pas complet (volontairement) et vous comprenez tout de suite pourquoi : L'écriture de 64 fois cette ligne à modifier chaque fois est fastidieuse : " If Tag = 8 Then PictureBox8.Image = e.Data.GetData(DataFormats.Bitmap) : LocationX(Tag) = PictureBox8.Location.X : LocationY(Tag) = PictureBox8.Location.Y"

L'utilisation de Tag a bien contribué à réduire l'écriture, l'idéal serait de pouvoir inclure la ligne précédente dans une boucle for/next de 1 à 64 par exemple mais comment l'indexer totalement les Picturebox et leurs propriétés ? D'autant qu'il va se rajouter beaucoup données supplémentaire sur cette ligne!

Pour info une photo de la feuille de capture et les propriétés mise à chaque case de 1 à 64 (Tag)

Nom : Ecranchess.JPG
Affichages : 687
Taille : 113,9 Ko

Merci pour vos idées et suggestions.