J'ai ouvert un nouveau projet.
J'ai nommé "Accueil" le formulaire d'accueil.
Sur ce formulaire, j'ai déposé
un contrôle bIni As Button, avec bIni.Text = "Initialiser"
un contrôle bInc As Button, avec bInc.Text = "Incrémenter"
un contrôle DGV As DataGridView
Dans ce formulaire, j'ai écrit le code suivant
Public Class Accueil
Private nX As Integer, nY As Integer, nC As Integer, Mots() As String
Private x As Integer, y As Integer, z As Integer
Public Sub New()
InitializeComponent()
nX = 4 : DGV.ColumnCount = nX
nY = 3 : DGV.RowCount = nY
nC = nY * nX
ReDim Mots(nC)
Mots(0) = "Que"
Mots(1) = "j"
Mots(2) = "aime"
Mots(3) = "à"
Mots(4) = "faire"
Mots(5) = "apprendre"
Mots(6) = "ce"
Mots(7) = "nom"
Mots(8) = "utile"
Mots(9) = "au"
Mots(10) = "sage"
Mots(11) = "!"
End Sub
Private Sub bIni_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bIni.Click
Initialiser()
End Sub
Private Sub bInc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bInc.Click
Incrémenter()
End Sub
Private Sub Initialiser()
x = 0 : y = 0 : z = 0
Afficher()
End Sub
Private Sub Incrémenter()
If x = nX - 1 Then
x = 0
If y = nY - 1 Then
MessageBox.Show("ça va pas, la tête?")
Else
y = y + 1
End If
Else
x = x + 1
End If
z = z + 1
Afficher()
End Sub
Private Sub Afficher()
DGV.Item(x, y).Value = Mots(z)
End Sub
End Class
À l'exécution, je clique une fois sur le bouton "Initialiser", puis plusieurs fois sur le bouton "Incrémenter".
Attrapez çà, et dites-moi si c'est votre pointure.
2 sept. 2013 à 08:42