Private Sub AjouterUneImage()
'Ajouter une image
Dim newImg As Control, newLab As Control, x&, N&, xctrl As Control
For Each xctrl In Controls
If xctrl.Name Like "Image##" Or xctrl.Name Like "Image#" Then
x = Val(Replace(xctrl.Name, "Image", "", , , vbTextCompare))
If x > N Then N = x
End If
Next
N = N + 1
Set newImg = Me.Controls.Add("Forms.image.1", "Image" & N, True)
Set newLab = Me.Controls.Add("Forms.label.1", "label" & (N + 2), True)
newLab.BorderStyle = fmBorderStyleSingle
End Sub
Sub AlignerLesImages()
'Aligner les images
Dim pasV!, pasH!, Wimg!, Himg!, W!, H!, Top0!, Left0!, N&, i&, x&, j&, xctrl As Control
For Each xctrl In Controls
If xctrl.Name Like "Image##" Or xctrl.Name Like "Image#" Then
x = Val(Replace(xctrl.Name, "Image", "", , , vbTextCompare))
If x > N Then N = x
End If
Next
pasV = Controls("Image5").Top - Controls("Image1").Top
pasH = Controls("Image2").Left - Controls("Image1").Left
W = Controls("Image1").Width: H = Controls("Image1").Height
Top0 = Controls("Image1").Top: Left0 = Controls("Image1").Left
For i = 2 To N
With Controls("Image" & i)
.Width = W: .Height = H
.Top = Top0 + pasV * Int((i - 1) \ 4)
.Left = Left0 + pasH * ((i - 1) Mod 4)
End With
Next i
W = Controls("Label3").Width: H = Controls("Label3").Height
Top0 = Controls("Label3").Top
For i = 3 To N + 2
With Controls("Label" & i)
.Width = W: .Height = H
.Top = Top0 + pasV * Int((i - 3) \ 4)
j = 1 + ((i - 3) Mod 4)
.Left = Controls("Image" & j).Left + (Controls("Image" & j).Width - W) / 2
End With
Next i
End Sub