Change image based on system date
I created an app in visual studio express 2008. I set a screen for SplashScreen with an image. I would like this picture changes depending on the season, so I went to my SplashScreen designer and found the line that corresponds to the image display:
Code:
Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.plus_beautiful_band
Where plus_beautiful_band is the name of my image.
I would like to put an If to see whether it is summer and put the beach, if it is autumn then we put leaves and so on for all season. The problem is that I do not know the code to do so. Maybe it is menu that I compare the date that corresponds to my season but I do not know the code.
Re: Change image based on system date
To do what? Do you know what season it is? Change the picture? The code to save an image you've posted. So I do not see what you lack
For the season, just know the season dates:
- Spring: March 21
- Summer: June 21
- Fall: September 21
- Winter: December 21
Re: Change image based on system date
Thank you for your reply. In fact I miss the code to retrieve the day and month (without the year) and the solution to compare date:
How can I tell him: - If the system date is greater than 21/03 and less than the 21/06 so ... the rest I know.
Re: Change image based on system date
To retrieve the month and day you just need your system time in a variable of type DateTime.
Code:
dim Dt as DateTime
Dt.Day 'for the day
Dt.month 'for the month
and you can compare a Date1.CompareTo (date2)
Quote:
Date1.CompareTo (date2)
compares the value of this instance to a System.DateTime instance and returns an integer that indicates whether this instance is earlier, later or equal to the specified DateTime
Re: Change image based on system date
Code:
Dim l_Date As DateTime
l_Date.Day
l_Date.Month
Visual Studio returns me the error:
Quote:
Standard access to the property must assign the property or use its value.
And after recovering my day and my month how I did for them together? Basically I want something like:
Code:
If DateSystem > 21/03 and DateSystem < 21/06 Then
Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.image_of_spring
Else
If DateSystem > 21/06 and DateSystem < 21/12hen
Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.image_of_winter
End If
End If
Except that it does not work. I'm not very good at programming, I do not understand everything
Re: Change image based on system date
This is a function that returns the season for a given date:
Code:
Public Enum Season
Spring
Summer
Autumn
Winter
End Enum
Public Shared Function GetSeason(ByVal dt As DateTime) As Season
Dim dSpring As DateTime = New DateTime(dt.Year, 3, 21)
Dim dSummer As DateTime = New DateTime(dt.Year, 6, 21)
Dim dAutumn As DateTime = New DateTime(dt.Year, 9, 21)
Dim dWinter As DateTime = New DateTime(dt.Year, 12, 21)
If dt < dSpring Then
Return Season.Winter
ElseIf dt < dSummer Then
Return Season.Spring
ElseIf dt < dAutumn Then
Return Season.Summer
ElseIf dt < dWinter Then
Return Season.Autumn
Else
Return Season.Winter
End If
End Function
To use it, you can do like this (assuming you had the resources in your application images Spring, Summer, Autumn and Winter):
Code:
Dim season As Season = GetSeason(DateTime.Today)
Select Case season
Case Season.Spring
Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Spring
Case Season.Summer
Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Summer
Case Season.Autumn
Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Autumn
Case Season.Winter
Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Winter
Case Else
' default case (should not occur...)
End Select