-
Notifications
You must be signed in to change notification settings - Fork 0
/
CALENDAR.frm
360 lines (320 loc) · 10.8 KB
/
CALENDAR.frm
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
VERSION 5.00
Begin VB.Form frmCalendar
AutoRedraw = -1 'True
BackColor = &H00FFFFFF&
BorderStyle = 4 'Fixed ToolWindow
Caption = "Calendario ..."
ClientHeight = 1890
ClientLeft = 5715
ClientTop = -375
ClientWidth = 2775
KeyPreview = -1 'True
LinkTopic = "Form3"
MaxButton = 0 'False
MinButton = 0 'False
PaletteMode = 1 'UseZOrder
ScaleHeight = 1890
ScaleWidth = 2775
ShowInTaskbar = 0 'False
Begin VB.PictureBox picMonth
BackColor = &H00C0C0C0&
ClipControls = 0 'False
BeginProperty Font
Name = "Trebuchet MS"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 1545
Left = 15
ScaleHeight = 1485
ScaleWidth = 2685
TabIndex = 0
Top = 345
Width = 2745
End
Begin PCGestion.chameleonButton lblPrev
Height = 285
Left = 30
TabIndex = 1
Top = 30
Width = 285
_ExtentX = 503
_ExtentY = 503
BTYPE = 9
TX = "<<"
ENAB = -1 'True
BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Trebuchet MS"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
COLTYPE = 1
FOCUSR = -1 'True
BCOL = 11513775
BCOLO = 11513775
FCOL = 0
FCOLO = 0
MCOL = 12632256
MPTR = 1
MICON = "CALENDAR.frx":0000
UMCOL = -1 'True
SOFT = 0 'False
PICPOS = 2
NGREY = 0 'False
FX = 0
HAND = 0 'False
CHECK = 0 'False
VALUE = 0 'False
End
Begin PCGestion.bsGradientLabel lblMonth
Height = 285
Left = 345
Top = 30
Width = 2070
_ExtentX = 3651
_ExtentY = 503
Caption = ""
BeginProperty Fount {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Trebuchet MS"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
CaptionColour = 0
Colour1 = 16761024
Colour2 = 16777152
CaptionAlignment= 1
End
Begin PCGestion.chameleonButton lblNext
Height = 285
Left = 2445
TabIndex = 2
Top = 30
Width = 285
_ExtentX = 503
_ExtentY = 503
BTYPE = 9
TX = ">>"
ENAB = -1 'True
BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "Trebuchet MS"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
COLTYPE = 1
FOCUSR = -1 'True
BCOL = 11513775
BCOLO = 11513775
FCOL = 0
FCOLO = 0
MCOL = 12632256
MPTR = 1
MICON = "CALENDAR.frx":001C
UMCOL = -1 'True
SOFT = 0 'False
PICPOS = 2
NGREY = 0 'False
FX = 0
HAND = 0 'False
CHECK = 0 'False
VALUE = 0 'False
End
End
Attribute VB_Name = "frmCalendar"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'Grid dimensions for days
Private Const GRID_ROWS = 6
Private Const GRID_COLS = 7
'Private variables
Private m_CurrDate As Date, m_bAcceptChange As Boolean
Private m_nGridWidth As Integer, m_nGridHeight As Integer
'Public function: If user selects date, sets UserDate to selected
'date and returns True. Otherwise, returns False.
Public Function GetDate(UserDate As Date, Optional Title) As Boolean
'Store user-specified date
m_CurrDate = UserDate
'Use caller-specified caption if any
If Not IsMissing(Title) Then
Caption = Title
End If
'Display this form
Me.Show vbModal
'Return selected date
If m_bAcceptChange Then
UserDate = m_CurrDate
End If
'Return value indicates if date was selected
GetDate = m_bAcceptChange
End Function
'Form initialization
Private Sub Form_Load()
'Center form on screen
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
'Calculate calendar grid measurements
m_nGridWidth = ((picMonth.ScaleWidth - Screen.TwipsPerPixelX) \ GRID_COLS)
m_nGridHeight = ((picMonth.ScaleHeight - Screen.TwipsPerPixelY) \ GRID_ROWS)
m_bAcceptChange = False
End Sub
Private Sub lblMonth_Click()
End Sub
'Process user keystrokes
Private Sub picMonth_KeyDown(KeyCode As Integer, Shift As Integer)
Dim NewDate As Date
Select Case KeyCode
Case vbKeyRight
NewDate = DateAdd("d", 1, m_CurrDate)
Case vbKeyLeft
NewDate = DateAdd("d", -1, m_CurrDate)
Case vbKeyDown
NewDate = DateAdd("ww", 1, m_CurrDate)
Case vbKeyUp
NewDate = DateAdd("ww", -1, m_CurrDate)
Case vbKeyPageDown
NewDate = DateAdd("m", 1, m_CurrDate)
Case vbKeyPageUp
NewDate = DateAdd("m", -1, m_CurrDate)
Case vbKeyReturn
m_bAcceptChange = True
Unload Me
Exit Sub
Case vbKeyEscape
Unload Me
Exit Sub
Case Else
Exit Sub
End Select
SetNewDate NewDate
KeyCode = 0
End Sub
'Double-click accepts current date
Private Sub picMonth_DblClick()
m_bAcceptChange = True
Unload Me
End Sub
' Select the date by mouse
Private Sub picMonth_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim i As Integer, MaxDay As Integer
'Determine which date is being clicked
i = Weekday(DateSerial(Year(m_CurrDate), Month(m_CurrDate), 1)) - 1
i = (((x \ m_nGridWidth) + 1) + ((y \ m_nGridHeight) * GRID_COLS)) - i
'Get last day of current month
MaxDay = Day(DateAdd("d", -1, DateSerial(Year(m_CurrDate), Month(m_CurrDate) + 1, 1)))
If i >= 1 And i <= MaxDay Then
SetNewDate DateSerial(Year(m_CurrDate), Month(m_CurrDate), i)
End If
End Sub
'Click on ">>" goes to next month
Private Sub lblNext_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button And vbLeftButton Then
SetNewDate DateAdd("m", 1, m_CurrDate)
End If
End Sub
'Double-click has same effect
Private Sub lblNext_DblClick()
SetNewDate DateAdd("m", 1, m_CurrDate)
End Sub
'Click on "<<" goes to previous month
Private Sub lblPrev_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button And vbLeftButton Then
SetNewDate DateAdd("m", -1, m_CurrDate)
End If
End Sub
'Double-click has same effect
Private Sub lblPrev_DblClick()
SetNewDate DateAdd("m", -1, m_CurrDate)
End Sub
'Changes the selected date
Private Sub SetNewDate(NewDate As Date)
If Month(m_CurrDate) = Month(NewDate) And Year(m_CurrDate) = Year(NewDate) Then
DrawSelectionBox False
m_CurrDate = NewDate
DrawSelectionBox True
Else
m_CurrDate = NewDate
picMonth_Paint
End If
End Sub
'Here's the calendar paint handler; displayes the calendar days
Private Sub picMonth_Paint()
Dim i As Integer, j As Integer, x As Integer, y As Integer
Dim NumDays As Integer, CurrPos As Integer, bCurrMonth As Boolean
Dim MonthStart As Date, buffer As String
'Determine if this month is today's month
If Month(m_CurrDate) = Month(Date) And Year(m_CurrDate) = Year(Date) Then
bCurrMonth = True
End If
'Get first date in the month
MonthStart = DateSerial(Year(m_CurrDate), Month(m_CurrDate), 1)
'Number of days in the month
NumDays = DateDiff("d", MonthStart, DateAdd("m", 1, MonthStart))
'Get first weekday in the month (0 - based)
j = Weekday(MonthStart) - 1
'Tweak for 1-based For/Next index
j = j - 1
'Show current month/year
lblMonth.Caption = Format$(m_CurrDate, "mmmm yyyy")
'Clear existing data
picMonth.Cls
'Display dates for current month
For i = 1 To NumDays
CurrPos = i + j
x = (CurrPos Mod GRID_COLS) * m_nGridWidth
y = (CurrPos \ GRID_COLS) * m_nGridHeight
'Show date as bold if today's date
If bCurrMonth And i = Day(Date) Then
picMonth.Font.Bold = True
Else
picMonth.Font.Bold = False
End If
'Center date within "date cell"
buffer = CStr(i)
picMonth.CurrentX = x + ((m_nGridWidth - picMonth.TextWidth(buffer)) / 2)
picMonth.CurrentY = y + ((m_nGridHeight - picMonth.TextHeight(buffer)) / 2)
'Print date
picMonth.Print buffer;
Next i
'Indicate selected date
DrawSelectionBox True
End Sub
'Draw or clears the selection box around the current date
Private Sub DrawSelectionBox(bSelected As Boolean)
Dim clrTopLeft As Long, clrBottomRight As Long
Dim i As Integer, x As Integer, y As Integer
'Set highlight and shadow colors
If bSelected Then
clrTopLeft = vbButtonShadow
clrBottomRight = vb3DHighlight
Else
clrTopLeft = vbButtonFace
clrBottomRight = vbButtonFace
End If
'Compute location for current date
i = Weekday(DateSerial(Year(m_CurrDate), Month(m_CurrDate), 1)) - 1
i = i + (Day(m_CurrDate) - 1)
x = (i Mod GRID_COLS) * m_nGridWidth
y = (i \ GRID_COLS) * m_nGridHeight
'Draw box around date
picMonth.Line (x, y + m_nGridHeight)-Step(0, -m_nGridHeight), clrTopLeft
picMonth.Line -Step(m_nGridWidth, 0), clrTopLeft
picMonth.Line -Step(0, m_nGridHeight), clrBottomRight
picMonth.Line -Step(-m_nGridWidth, 0), clrBottomRight
End Sub