Concatener une picture box et un entier

Résolu
niakwel Messages postés 16 Date d'inscription mardi 5 août 2008 Statut Membre Dernière intervention 22 mars 2009 - 21 mars 2009 à 19:22
niakwel Messages postés 16 Date d'inscription mardi 5 août 2008 Statut Membre Dernière intervention 22 mars 2009 - 22 mars 2009 à 00:02
je suis néophyte en vb, je fais un jeu de memory pour un projet de bts,
pour placer les cartes de façon aléatoire de voudrais faire une boucle qui place les picture box de façon aléatoire

j'ai donc une boucle

        For i = 1 To 16
            picturebox(i)
            End If
        Next i

je voudrais donc avoir picturebox1, picturebox2, picturebox3...

Est ce possible?

Merci de vos réponses

7 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
21 mars 2009 à 21:38
pas de groupe de controles en VB.Net, comme te l'a dit jmf0

utilises un tableau ...
3
jmf0 Messages postés 1566 Date d'inscription mardi 26 décembre 2000 Statut Membre Dernière intervention 5 avril 2013 8
21 mars 2009 à 20:22
> une recherche sur ce forum te permettra de trouver une réponse à cette question plus que récurrente !:
2) ton end if sans if est plus que surprenant dans :
For i = 1 To 16
            picturebox(i)
            End If
Next i

sans parler du reste (que ferait donc un picturebox(i) sans rien d'autre ????)
0
niakwel Messages postés 16 Date d'inscription mardi 5 août 2008 Statut Membre Dernière intervention 22 mars 2009
21 mars 2009 à 20:37
c'était juste une partie de l'exemple, la boucle entière donnerait :

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Placement As New Random
        Dim CarteTiree As Integer

        Dim i As Integer

        TextBox1.Text = Score
        Randomize()

        For i = 1 To 16
            CarteTiree = Placement.Next(16)
            If i = 1 Then
                 picturebox(CarteTiree).location=10,20
            End If
                if i=2 then
                picturebox(CarteTiree).location=10,20
        Next i

Vala vala je vais regarder un peu le groupe de contrôle indexé, merci de ta réponse
0
jmf0 Messages postés 1566 Date d'inscription mardi 26 décembre 2000 Statut Membre Dernière intervention 5 avril 2013 8
21 mars 2009 à 21:37
Ah !
Tu croiis que c'est mieuix, ainsi exposé ???Si (cette fois-ci) ton code est "complet", on ne pourra que s'interroger sur tes deux conditions (si i 1 ou si i 2) puisque, dans un cas comme dans l'autre, on exécute une instruction rigoureusement identique :
picturebox(CarteTiree).location=10,20
!!!
Et j'espère pour toi que ton code montré n'est toujours pas complet, car ton second If n'est pas "fermé" par un End If !

Et si tu commençais à t'appliquer un peu, au moins pour copier-coller ton code sur ce forum ?
Ce serait bien et un peu moins "zazou" ...
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
niakwel Messages postés 16 Date d'inscription mardi 5 août 2008 Statut Membre Dernière intervention 22 mars 2009
21 mars 2009 à 22:22
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Placement As New Random
        Dim CarteTiree As Integer

        Dim i As Integer

        TextBox1.Text = Score
        Randomize()

        For i = 1 To 16
            CarteTiree = Placement.Next(16)
            If i = 1 Then

                 picturebox(CarteTiree
).location=15,20
            End If
                if i=2 then

                picturebox(CarteTiree
).location=92,20
             end if

            If i = 3 Then

                 picturebox(CarteTiree
).location=169,20
            End If

            If i = 4 Then

                 picturebox(CarteTiree
).location=246,20
            End If

            If i = 5 Then

                 picturebox(CarteTiree
).location=15,95
            End If

            If i = 6 Then

                 picturebox(CarteTiree
).location=
92,95


            End If

            If i = 7 Then

                 picturebox(CarteTiree
).location=
169
,95
            End If

            If i = 8 Then

                 picturebox(CarteTiree
).location=246,95
            End If


            If i = 9 Then

                 picturebox(CarteTiree
).location=15,170
            End If
                if i=10 then

                picturebox(CarteTiree
).location=92,170

             end if

            If i = 11 Then

                 picturebox(CarteTiree
).location=169,170
            End If

            If i = 12 Then

                 picturebox(CarteTiree
).location=246,170
            End If

            If i = 13 Then

                 picturebox(CarteTiree
).location=15,245
            End If

            If i = 14 Then

                 picturebox(CarteTiree
).location=
92,245


            End If

            If i = 15 Then

                 picturebox(CarteTiree
).location=
169
,245
            End If

            If i = 16 Then

                 picturebox(CarteTiree
).location=246,245
            End If


        Next i
End Sub
0
niakwel Messages postés 16 Date d'inscription mardi 5 août 2008 Statut Membre Dernière intervention 22 mars 2009
21 mars 2009 à 23:20
Ok Renfiled, j'ai donc revu mon code, j'ai créé un tableau ou je mets les coordonnées des différentes cartes et je vais initialiser chacune des PictureBox grace à ça, j'ai maintenant un autre problème : quand j'essaye de modifier la propriété location.x j'ai un message d'erreur : Property access must assign to the property or use its value. 
ci joint le code

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

        TextBox1.Text = Score
        Dim Placement As New Random
        Dim CarteTiree As Integer

        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        Dim l As Integer
        Dim m As Integer

        Dim Table(16, 3) As Integer

        Randomize()

        For j = 0 To 3
            Table(j, 2) = 20
            Table(j * 4, 1) = 15
        Next j

        For k = 0 To 3
            Table(k + 4, 2) = 95
            Table(k * 4 + 1, 1) = 92
        Next k

        For l = 0 To 3
            Table(l + 8, 2) = 170
            Table(l * 4 + 2, 1) = 169
        Next l

        For m = 0 To 3
            Table(m + 12, 2) = 245
            Table(m * 4 + 3, 1) = 246
        Next m

        CarteTiree = Placement.Next(16)
        PictureBox1.Location.X(Table(CarteTiree + 1, 1))
        PictureBox1.Location.Y(Table(CarteTiree + 1, 2))
0
niakwel Messages postés 16 Date d'inscription mardi 5 août 2008 Statut Membre Dernière intervention 22 mars 2009
22 mars 2009 à 00:02
le secret c'était de mettre
PictureBox1.Location = New Point(Table(CarteTiree1, 1), Table(CarteTiree1, 2))
0
Rejoignez-nous