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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
' '******************************** CREATION CONTROL CALENDRIER DYNAMIQUE************************************
' ' Auteur: Chamalin2@hotmail.fr alias patricktoulon sur developpez.com *
' ' exemplaire pour DVP.com *
' ' ---------------------- *
' ' date de creation : 23/07/2016 *
' ' derniere mise ajour: *
' ' 1 aout 2016 : ajout du placement relatif *
' ' 2 aout 2016 :ajout du tiptext en cas de petite taille du calendrier *
' ' licence: libre a condition de citer l'auteur *
' ' *
' ' *
' ' 15/01/2017 *
' ' NOUVELLE VERSION !!!!! *
' ' on peut maintenant l'utiliser sur plusieur textboxs dynamiquement avec la meme classe *
' '**********************************************************************************************************
Option Explicit
Public WithEvents JRS As MSForms.Label
Public WithEvents formm As UserForm
Public WithEvents frame As MSForms.frame
Public WithEvents calendart As MSForms.TextBox
Public WithEvents listeA As MSForms.ComboBox
Public WithEvents listeM As MSForms.ComboBox
Public WithEvents listeF As MSForms.ComboBox
Public WithEvents memo As MSForms.TextBox
Private jr(42) As New calendrier2
Private tcal(50) As New calendrier2
Private usf As New calendrier2
Function NB_JOURS(mois, année)
NB_JOURS = Day(DateSerial(année, mois + 1, 1) - 1)
End Function
Function createcalendrier(uf)
Set usf.formm = uf
Dim jourr, formT, fram, listm, lista, listf, i, bout As Object, M, leleft, thetop, lig, col, ctrl, T
jourr = Array("lun.", "mar.", "mer.", "jeu.", "ven.", "sam.", "dim.")
formT = Array("FORMAT", "dd/mm/yyyy", "dd-mm-yyyy", "d/m/yy", "yyyy/mm/dd", "yyyy-mm-dd", "ddd dd mmm yyyy", "dddd dd mmmm yyyy")
Set fram = uf.Add("Forms.Frame.1", "cal")
With fram: .Width = 160: .Height = 130: .BackColor = RGB(80, 80, 80): .BorderStyle = 1: .BorderColor = vbBlue: End With
Set M = fram.Add("Forms.TextBox.1", "memo")
Set usf.frame = fram
'*********************************************ajout le la liste des mois *********************************************
Set listm = fram.Add("Forms.combobox.1", "listemois")
With listm
.ListRows = 12: .Font.Size = 9: .TextAlign = 1: .Move 0, 0, (fram.Width / 3) + 10, 15
.BackColor = RGB(150, 150, 150): .ForeColor = RGB(0, 0, 0)
For i = 1 To 12: .AddItem Format("01/0" & i & "/2016", "mmmm"): Next
.Value = Format(Date, "mmmm"): .BorderStyle = 1: .ListRows = UBound(formT)
End With
'*******************************************Ajout de la combobox année***************************************************
Set lista = fram.Add("Forms.combobox.1", "listeAnnée")
With lista
.ListRows = 15: .Font.Size = 9: .TextAlign = 1: .Move listm.Width, 0, (fram.Width / 3) - 10, 15: .BackColor = RGB(150, 150, 150): .ForeColor = RGB(0, 0, 0):
For i = 1800 To Val(Year(Date)) + 50: .AddItem i: Next
.Value = Year(Date): .BorderStyle = 1
End With
'*******************************************Ajout de la combobox choix du format de sortie de la date ***************************************************
Set listf = fram.Add("Forms.combobox.1", "listeFormat")
With listf
.ListRows = 15: .Font.Size = 9: .TextAlign = 1: .Move (fram.Width / 3) * 2, 0, (fram.Width / 3), 15: .BackColor = RGB(150, 150, 150): .ForeColor = RGB(0, 0, 0): .BorderStyle = 1
.List = formT
.ListIndex = 1
End With
'************************************************************************************************
For i = 0 To UBound(jourr) ' ajout de la ligne d'entetes pour les jours en lettre
Set bout = fram.Add("Forms.lABEL.1", jourr(i))
With bout
.Caption = jourr(i): .Tag = i + 1: .BorderStyle = 1: .BackStyle = 1: .BackColor = RGB(70, 70, 70): .BorderColor = RGB(0, 200, 255): .ForeColor = RGB(255, 255, 255)
.TextAlign = 2: .FontSize = 8
.Move leleft + (23 * i) - 1 * i, listf.Height + 1, 23, Round(fram.Height / 8)
End With
Next
'**************************************************************************************************
thetop = fram.Controls("lun.").Top + fram.Controls("lun.").Height + 2
i = 0
For lig = 1 To 6
For col = 0 To 6
i = i + 1
Set bout = fram.Add("Forms.Label.1", "jour" & i)
With bout
.BorderStyle = 1: .BackStyle = 1: .BackColor = RGB(120, 120, 120): .BorderColor = RGB(255, 255, 255): .ForeColor = RGB(255, 255, 255)
.TextAlign = 2: .FontSize = 7
.FontSize = IIf(.FontSize < 7, 7, .FontSize)
.Move leleft + (23 * col) - 1 * col, thetop, 23, Round(fram.Height / 8)
'ajout des liste,frame,userform,textbox dans l'instance(i) de la classe calendrier du label
With jr(i): Set .JRS = bout: Set .listeA = lista: Set .listeM = listm: Set .listeF = listf: Set .formm = uf: Set .memo = M: Set .frame = fram: End With
End With
If col = 6 Or col = 14 Or col = 21 Or col = 28 Or col = 35 Or col = 42 Then thetop = thetop + 15: leleft = 0
Next col
Next lig
'****************************************************************************************
For Each ctrl In uf.Controls
If TypeName(ctrl) = "TextBox" And ctrl.Tag = "cal" Then
T = T + 1: ctrl.Tag = Format(Date, "dd/mm/yyyy")
With tcal(T): Set .calendart = ctrl: Set .listeA = lista: Set .listeM = listm: Set .frame = fram: Set .formm = uf: Set .memo = M: End With
End If
Next
mise_a_jour fram
fram.Visible = False
End Function
Private Sub JRS_Click()
If JRS.Caption = "" Then frame.Visible = False: Exit Sub
Dim F As String
F = IIf(listeF.Value = "FORMAT", "dd/mm/yyyy", listeF.Value)
formm.Controls(memo.Tag) = Format(JRS.Caption & "/" & listeM.ListIndex + 1 & "/" & listeA.Value, F)
formm.Controls(memo.Tag).Tag = Format(JRS.Caption & "/" & listeM.ListIndex + 1 & "/" & listeA.Value, "dd/mm/yyyy")
frame.Visible = False
listeF.ListIndex = 0
End Sub
Private Sub JRS_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If JRS.BackColor = RGB(120, 120, 120) Then
If frame.Tag <> "" Then
frame.Controls(frame.Tag).BackColor = RGB(120, 120, 120): frame.Controls(frame.Tag).BorderColor = vbWhite
If frame.Controls(frame.Tag).ForeColor <> vbGreen Then frame.Controls(frame.Tag).ForeColor = vbWhite
End If
If JRS.Caption <> "" Then JRS.BackColor = RGB(100, 100, 100): JRS.BorderColor = RGB(0, 200, 255)
If JRS.ForeColor <> vbGreen Then JRS.ForeColor = RGB(255, 0, 100)
JRS.Parent.Tag = JRS.Name
End If
End Sub
Sub mise_a_jour(fram)
Dim ctrl, i As Long, jj, decal
For i = 1 To 42: fram.Controls("jour" & i).Caption = "": Next
decal = Val(fram.Controls(Format(DateSerial(fram.Controls("listeAnnée").Value, fram.Controls("listemois").ListIndex + 1, 1), "ddd")).Tag)
For i = 1 To NB_JOURS(fram.Controls("listemois").ListIndex + 1, fram.Controls("listeAnnée").Value)
fram.Controls("jour" & i + decal - 1) = i
If DateSerial(fram.Controls("listeAnnée").Value, fram.Controls("listemois").ListIndex + 1, i) = Date Then fram.Controls("jour" & i + decal - 1).ForeColor = vbGreen Else fram.Controls("jour" & i + decal - 1).ForeColor = vbWhite
fram.Controls("jour" & i + decal - 1).ControlTipText = Format(DateSerial(fram.Controls("listeAnnée").Value, fram.Controls("listemois").ListIndex + 1, i), "dddd dd mmmm yyyy")
Next
End Sub
Private Sub frame_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If frame.Tag <> "" Then
frame.Controls(frame.Tag).BackColor = RGB(120, 120, 120): frame.Controls(frame.Tag).BorderColor = vbWhite
If frame.Controls(frame.Tag).ForeColor <> vbGreen Then frame.Controls(frame.Tag).ForeColor = vbWhite
frame.Tag = ""
End If
End Sub
Private Sub listeM_Change()
mise_a_jour listeM.Parent
End Sub
Private Sub listeA_Change()
mise_a_jour listeM.Parent
End Sub
Private Sub calendart_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim Wi As Long, HT As Long
Wi = calendart.Parent.Width: HT = calendart.Parent.Height
memo.Tag = calendart.Name
With frame
.Visible = True
.Left = IIf(Wi - calendart.Left + 10 >= .Width, calendart.Left, Wi - (frame.Width + 10))
.Top = IIf(HT - calendart.Top + 10 >= .Height, calendart.Top, HT - (frame.Height + 10))
End With
formm.Repaint 'accelere l'affichage
listeM.ListIndex = Month(calendart.Tag) - 1
listeA.Value = Year(calendart.Tag)
End Sub
Private Sub formm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
frame.Visible = False
End Sub |
Partager