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
| Option Explicit
'Généralisation des dimensions et nombre de labels
Const Nc As Integer = 20 'nombre de labels en colonnes
Const Nl As Integer = 15 'nombre de labels en lignes
Const L As Integer = 20 'largeur des labels
Const H As Integer = 12 'hauteur des labels
Const Ec As Integer = 5 'Ecart horizontal entre labels
Const El As Integer = 2 'Ecart vertical entre labels
Dim Couleur() As Long 'On peut s'en passer si tous les labels ont la même couleur
Dim old
Dim sweb
Dim calco
Dim swebleft
Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim bouton
bouton = calco.elementFromPoint(X, Y).ID
MsgBox bouton
End Sub
Private Sub Image1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim bouton
bouton = calco.elementFromPoint(X, Y).ID
If bouton = "" And old <> 0 Then Me.Controls(old).BackColor = Couleur(Replace(old, "LB", ""))
If bouton <> "" Then
If bouton <> old And old <> 0 Then Me.Controls(old).BackColor = Couleur(Replace(old, "LB", ""))
Me.Controls(bouton).BackColor = vbRed
old = bouton
Me.Caption = bouton
End If
End Sub
Private Sub UserForm_Initialize()
Dim i As Integer, j As Integer, k As Integer
Dim Lbl As Control
Dim ctrl As Object, codehtml
swebleft = (Nc + Ec + 1) * L
'Règlage de la taille et la position du contrôle image
With Me.Image1
.Left = 0
.Top = 0
.Width = Nc * (L + Ec) + 2 * Ec
.Height = Nl * (H + El) + 2 * El
.ZOrder 0
.BackStyle = 0
.BorderStyle = 0
End With
Set sweb = Controls.Add("Shell.Explorer.2", "web", True): sweb.Left = swebleft: sweb.Width = (Nc + Ec) * L + 30: sweb.Height = (Nl + El) * H + 30
sweb.navigate "about:blank": Set calco = sweb.Document
codehtml = codehtml & "<html><head><meta http-equiv=""X-UA-Compatible"" content=""IE=10""></head><body style="" font-size:10;"">"
ReDim Couleur(1 To Nc * Nl)
For i = 1 To Nl
For j = 1 To Nc
k = Nc * (i - 1) + j
Set Lbl = Me.Controls.Add("Forms.Label.1", "LB" & k, True)
With Lbl
.Left = Ec + ((L + Ec) * (j - 1))
.Top = El + ((H + El) * (i - 1))
.Width = L
.Height = H
.Caption = "LB" & k
.TextAlign = 2
.BorderStyle = 1
.ZOrder 1
.Tag = "classe"
.BackColor = ThisWorkbook.Colors(3 + (Rnd * 53))
Couleur(k) = .BackColor
codehtml = codehtml & "<div id=""" & .Name & """ style=""position:absolute;left:" & .Left & "px;top:" & .Top & "px;width:" & .Width - 2 & "px;height:" & .Height - 1 & "px;border:1px solid red""></div>"
End With
Next j
Next i
codehtml = codehtml & "</body></html>"
calco.write Replace(codehtml, "><", ">" & vbCrLf & "<")
old = 0
End Sub |