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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| Option Explicit
Public WithEvents framm As MSForms.Frame
Public WithEvents formm As UserForm
Public WithEvents selecté As MSForms.TextBox
Public WithEvents labLt As MSForms.Label
Public WithEvents grille As MSForms.Frame
Public WithEvents combo As MSForms.ComboBox
Public WithEvents comboseule As MSForms.ComboBox
Public WithEvents scrol As MSForms.ScrollBar
Private usf(100) As New combofake3
Function combocolor3(comb, bicolorbyrow, Optional GriDline As Boolean = False, Optional GrildLineColor As Variant = vbBlack, Optional overcolor As Variant = vbCyan, Optional listrow As Variant = False)
Dim cW, ecW#, ecL#, Fram, Ssel, Drop, cadr, lig#, col#, cc#, ccol#, cel, mabarre, bouton, countrows#, ccwidth#, Hheight, lab, scro, ccc, i, grille
comb.Parent.Tag = overcolor 'memorisation de la couleur OVER dans tag du userform
cW = Split(Replace(comb.ColumnWidths, " pt", ""), ";") 'columnwidths de la combobobox originale vers un array
For i = 0 To UBound(cW): ccc = ccc + Val(cW(i)): Next
If listrow = False Then listrow = comb.ListRows
Set lab = comb.Parent.Controls.Add("Forms.label.1", "memo" & col, True)
With lab: .Caption = listrow - 1: .Font.Size = comb.Font.Size: .AutoSize = True: Hheight = .Height + 0.5: .Top = -15: End With
'ajout du textbox (combobox
Set Ssel = comb.Parent.Controls.Add("Forms.textbox.1", "selectio", True)
With Ssel: .Move comb.Left + 2, comb.Top + 2, comb.Width - comb.Height + 2, comb.Height - 4: .BorderStyle = 1: .BorderColor = vbWhite: End With
'ajout du cadre complet
Set cadr = comb.Parent.Controls.Add("Forms.Frame.1", "fondcombo", True): cadr.BackColor = &H8000000F: cadr.BorderStyle = 1: cadr.Visible = False
With cadr: .Move comb.Left, comb.Top + comb.Height - 1, comb.Width, (Hheight * listrow) + IIf(ccc > comb.Width, 14, 4): End With
'ajout du cadre grille
Set grille = cadr.Controls.Add("Forms.Frame.1", "grille", True): grille.BackColor = &H8000000F: grille.BorderStyle = 1: grille.Visible = True
With grille: .Move -1, 1, cadr.Width - 13, (Hheight * listrow) + IIf(ccc > comb.Width, 14, 1):
.Width = IIf(listrow - 1 = comb.ListCount - 1, cadr.Width, cadr.Width - 13)
If ccc > .Width Then .ScrollBars = 1: .ScrollWidth = ccc + 1
End With
'ajout de la scrollbars verticale
Set scro = cadr.Controls.Add("Forms.scrollbar.1", "scrol", True)
With scro: .Move cadr.Width - 13, 0 + 1, 12, IIf(ccc > comb.Width, cadr.Height - 14, cadr.Height - 2): scro.Tag = listrow - 1:
scro.Visible = IIf(listrow - 1 = comb.ListCount - 1, False, True): scro.Max = (comb.ListCount - 1) - listrow + 1: .LargeChange = 1: End With
For lig = 0 To listrow - 1
ccol = 0
For col = 0 To comb.ColumnCount - 1
cc = cc + 1 'DECOMPTE pour alimenter les sousclasses(usf(1 a X)
'ajout item(ligne/colonne)
Set cel = grille.Controls.Add("Forms.label.1", "Lig" & lig & "Ligcol" & col, True)
With cel
.Caption = " " & comb.List(lig, col): .Height = Hheight: .Font.Size = comb.Font.Size - 1: 'alimentation des propriétés
.BorderStyle = IIf(GriDline, 1, 0) 'bordure(gridline)
.BorderColor = IIf(GriDline, GrildLineColor, .BackColor) 'couleur du gridline
.WordWrap = False:
.ForeColor = comb.ForeColor
.Left = 1 + ccol + IIf(col > 1, -(1 * col), 0): .Width = cW(col): .Top = (.Height * lig):
If col = comb.ColumnCount - 1 And ccol < grille.Width - 10 Then .Width = .Width + (grille.Width - 10) - ccol - 5
.BackColor = IIf(lig Mod 2 = 0, bicolorbyrow(1), bicolorbyrow(0)): .Tag = .BackColor 'memorisation du backcolor du label pour le rollOVER
'enregistrement des parties dans les sousclasses pour la gestion des evenements (click,move)
Set usf(cc).formm = comb.Parent: Set usf(cc).framm = cadr: Set usf(cc).grille = grille: Set usf(cc).combo = comb:
Set usf(cc).labLt = cel: Set usf(cc).selecté = Ssel: Set usf(cc).scrol = scro: Set usf(100).comboseule = comb
End With
ccol = ccol + Val(cW(col))
Next
Next
comb.Parent.Repaint
End Function
Private Sub scrol_Change()
Dim cc, lig, col, LroW
cc = -1: LroW = scrol.Tag
For lig = scrol.Value To LroW + scrol.Value
For col = 0 To combo.ColumnCount - 1: cc = cc + 1: grille.Controls(cc) = " " & combo.List(lig, col): Next
Next
End Sub
Private Sub scrol_Scroll()
Dim cc, lig, col, LroW, Sv
cc = -1: LroW = scrol.Tag: Sv = scrol.Value
For lig = Sv To LroW + Sv: For col = 0 To combo.ColumnCount - 1: cc = cc + 1: grille.Controls(cc) = " " & combo.List(lig, col): Next: Next
End Sub
Private Sub labLt_Click()
formm.Controls(combo.Name).Tag = Split(labLt.Name, "col")(1) 'memorisation de l'index colonne dans le tag de la combobox originale
formm.Controls(combo.Name).ListIndex = scrol.Value + Val(Split(labLt.Name, "Lig")(1)) 'modification de la propriété listindex de la combobox originale
selecté.Value = Mid(labLt.Caption, 3, 1000) 'le textbox de substitution du haut de la combobox prent la valeur de l'item cliqué(ligne/colonne)
framm.Visible = False: scrol.Visible = False 'fermeture frame(imite le comportement de l'originale
End Sub
Private Sub selecté_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
framm.Visible = False:
End Sub
Private Sub selecté_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If framm.Tag <> "" Then
If framm.Tag <> labLt.Name Then framm.Controls(framm.Tag).BackColor = framm.Controls(framm.Tag).Tag
End If
framm.Tag = labLt.Name
labLt.BackColor = formm.Controls(1).Parent.Tag
End Sub
Private Sub labLt_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim i#
If framm.Tag <> "" Then
If framm.Tag <> labLt.Name Then framm.Controls(framm.Tag).BackColor = framm.Controls(framm.Tag).Tag
End If
framm.Tag = labLt.Name
labLt.BackColor = formm.Controls(1).Parent.Tag
End Sub
'remise de la couleur initiale sur l'evenement frame et userform
Private Sub framm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If framm.Tag <> "" Then framm.Controls(framm.Tag).BackColor = framm.Controls(framm.Tag).Tag
End Sub
Private Sub formm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If framm.Tag <> "" Then framm.Controls(framm.Tag).BackColor = framm.Controls(framm.Tag).Tag
End Sub
Private Sub formm_Click()
framm.Visible = False: scrol.Visible = False 'fermeture frameet scroll(imite le comportement de l'originale
'fermeture de la fram(imite le comportement de l'originale)
End Sub
Private Sub comboseule_DropButtonClick()
Dim f
comboseule.Enabled = False
comboseule.Enabled = True
Set f = comboseule.Parent.Controls("fondcombo")
If f.Visible = True Then
f.Visible = False
Else
f.Visible = True
End If
With comboseule: .Parent.Controls("scrol").Visible = IIf(.Parent.Controls("scrol").Tag - 1 = comboseule.ListCount - 1, False, True): End With
comboseule.Parent.Repaint
End Sub |
Partager