The following code permits a developer to select a color based on a season of the year.
Code:
Module Seasons
Public Enum Season
Spring = 0
Summer = 1
Autumn = 2
Winter = 3
End Enum
''' <summary>
''' Return the season for the date passed in
''' </summary>
''' <param name="sender">Date</param>
''' <returns>A member of Season Enum</returns>
''' <remarks>Seasons are generally subjective where they begin and end, feel free to keep silent</remarks>
Public Function GetSeason(ByVal sender As Date) As Season
Dim value As Single = CSng(sender.Month) + sender.Day \ 100 ' <month>.<day(2 digit)>
If value < 3.21 OrElse value >= 12.22 Then
Return Season.Winter
End If
If value < 6.21 Then
Return Season.Spring
End If
If value < 9.23 Then
Return Season.Summer
End If
Return Season.Autumn
End Function
''' <summary>
''' Return a seasonal color for a date
''' </summary>
''' <param name="sender">Date</param>
''' <returns></returns>
''' <remarks>Date is generally the current date</remarks>
Public Function GetSeasonColor(ByVal sender As Date) As Color
Dim c As Color
Select Case GetSeason(Now)
Case Season.Autumn
c = Color.Brown
Case Season.Spring
c = Color.Pink
Case Season.Summer
c = Color.Purple
Case Season.Winter
c = Color.White
End Select
Return c
End Function
''' <summary>
''' Set control background color to a pre-defined color for the current season
''' </summary>
''' <param name="sender">Control</param>
''' <remarks></remarks>
<System.Diagnostics.DebuggerHidden()> _
<System.Runtime.CompilerServices.Extension()> _
Public Sub SeasonalBackColor(ByVal sender As Control)
sender.BackColor = GetSeasonColor(Now)
End Sub
End Module
Set current form's BackColor
Code:
Me.SeasonalBackColor()
Set a button's BackColor
Code:
cmdClose.SeasonalBackColor()
Please note I am sane but had a customer who asked for this.