Hello All
It's been years since I've programmed VB and it seems I've forgotten more than I remember. I'm just working on a simple calendar (based on someone else's code) and I'm trying to change the BackColor of the empty panels in a FlowLayoutPanel. If there is no label text then the panel would be a different color. It's not really important to the calendar, but it's bugging me that I can't figure it out myself(even though I'm sure it's simple). Thanks in advance.
It's been years since I've programmed VB and it seems I've forgotten more than I remember. I'm just working on a simple calendar (based on someone else's code) and I'm trying to change the BackColor of the empty panels in a FlowLayoutPanel. If there is no label text then the panel would be a different color. It's not really important to the calendar, but it's bugging me that I can't figure it out myself(even though I'm sure it's simple). Thanks in advance.
Code:
Private Sub GenerateDayPanel(ByVal totalDays As Integer)
flDays.Controls.Clear()
listFlDay.Clear()
Dim pflowh As Integer
pflowh = pnlFlow.Height
For i As Integer = 1 To totalDays
Dim fl As New FlowLayoutPanel
fl.Name = $"flDay{i}"
fl.Width = Label1.Width
fl.Height = pflowh / 6
fl.Margin = New Padding(0)
fl.BackColor = Color.DimGray
fl.BorderStyle = BorderStyle.FixedSingle
fl.Cursor = Cursors.Hand
fl.AutoScroll = True
' AddHandler fl.Click, AddressOf AddNewAppointment
flDays.Controls.Add(fl)
listFlDay.Add(fl)
Next
End Sub
Code:
Private Sub AddLabelDayToFlDay(ByVal startDayAtFlNumber As Integer, ByVal totalDaysInMonth As Integer)
For Each fl As FlowLayoutPanel In listFlDay
fl.Controls.Clear()
fl.Tag = 0
fl.BackColor = Color.White
Next
Dim myMargin = New Padding
myMargin.All = 0
For i As Integer = 1 To totalDaysInMonth
Dim lbl As New Label
lbl.Name = $"lblDay{i}"
lbl.AutoSize = False
lbl.TextAlign = ContentAlignment.TopLeft
lbl.Margin = myMargin
lbl.Text = i
lbl.Font = New Font("Microsoft Sans Serif", 18)
listFlDay((i - 1) + (startDayAtFlNumber - 1)).Tag = i
listFlDay((i - 1) + (startDayAtFlNumber - 1)).Controls.Add(lbl)
If New Date(currentDate.Year, currentDate.Month, i) = Date.Today Then
listFlDay((i - 1) + (startDayAtFlNumber - 1)).BackColor = Color.Aqua
End If
Next
End Sub