Results 1 to 3 of 3

Thread: Seasonal colors

  1. #1

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Seasonal colors

    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.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Seasonal colors

    Does it account for the seasons being a bit confused such as that seem to be this year?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: Seasonal colors

    Quote Originally Posted by Nightwalker83 View Post
    Does it account for the seasons being a bit confused such as that seem to be this year?
    Read the remarks in the code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width