-
Dec 6th, 2024, 08:57 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Systray icon sending notifications
I have created a small program that sets dates in the registry and then downsizes into the systray / notification area. My program looks at those dates in the registry and if one date is today, popup a notification telling the user. But what I have noticed is my program only works for the first few minutes as the date never gets updated in the app. I can double click the app and it shows but has the today's date as the date I sent it to the systray. I used .refresh() on labels and stuff but not working. How do I get the systray icon to get current date or keep refreshing itself? Once the program gets sent to the systray it starts a timer loop, mainly checking for matching dates. but as I said it appears to keep matching the date when it had when it went to the systray.
How do I get the program to keep refreshing the date when sent down to systray?
-
Dec 6th, 2024, 09:30 AM
#2
Re: Systray icon sending notifications
Originally Posted by phpman
I have created a small program that sets dates in the registry and then downsizes into the systray / notification area. My program looks at those dates in the registry and if one date is today, popup a notification telling the user. But what I have noticed is my program only works for the first few minutes as the date never gets updated in the app. I can double click the app and it shows but has the today's date as the date I sent it to the systray. I used .refresh() on labels and stuff but not working. How do I get the systray icon to get current date or keep refreshing itself? Once the program gets sent to the systray it starts a timer loop, mainly checking for matching dates. but as I said it appears to keep matching the date when it had when it went to the systray.
How do I get the program to keep refreshing the date when sent down to systray?
Is the timer being triggered when the app is minimized? How are you comparing dates?
If possible could you post the code that you suspect isn't behaving correctly.
-
Dec 6th, 2024, 10:15 AM
#3
Thread Starter
Frenzied Member
Re: Systray icon sending notifications
sure thing
Code:
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
NotifyIcon1.Visible = True
Me.ShowInTaskbar = False
Me.Hide()
Dim Todayd As Date = Date.Now.ToString("MM/d/yyyy")
';NotifyIcon1.BalloonTipText = "Hi from right system tray"
'NotifyIcon1.Text = Date.Now.ToString("MM/d/yyyy H:mm:ss") ' doesn't update on each mouse over
If My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing).length > 0 Then
MarchResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing)
Dim TDiffm = DateDiff(DateInterval.Day, Todayd, MarchResDate)
'Dim TDiff As TimeSpan = MarchResDate.Subtract(Today)
'MessageBox.Show(TDiff.Minutes.ToString)
If TDiffm <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
NotifyIcon1.ShowBalloonTip(500)
MessageBox.Show("Time to Reserve For March")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing).length > 0 Then
MayResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing)
Dim TDiffmay = DateDiff(DateInterval.Day, Todayd, MayResDate)
' Dim TDiffmay As TimeSpan = MayResDate.Subtract(Today)
' MessageBox.Show(TDiffmay.ToString)
If TDiffmay <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
NotifyIcon1.ShowBalloonTip(500)
MessageBox.Show("Time to Reserve For May")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing).length > 0 Then
JulyResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing)
Dim TDiffj = DateDiff(DateInterval.Day, Todayd, JulyResDate)
'Dim TDiffj As TimeSpan = JulyResDate.Subtract(Today)
'MessageBox.Show(Today.ToString & " - " & JulyResDate.ToString & " - " & TDiff.ToString)
If TDiffj <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
NotifyIcon1.ShowBalloonTip(500)
MessageBox.Show("Time to Reserve For July")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing).length > 0 Then
SeptResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing)
Dim TDiffs = DateDiff(DateInterval.Day, Todayd, SeptResDate)
'Dim TDiffs As TimeSpan = SeptResDate.Subtract(Today)
If TDiffs <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
NotifyIcon1.ShowBalloonTip(500)
MessageBox.Show("Time to Reserve For Sept")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing).length > 0 Then
NewYearResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing)
Dim TDiffd = DateDiff(DateInterval.Day, Todayd, NewYearResDate)
'Dim TDiffd As TimeSpan = NewYearResDate.Subtract(Today)
If TDiffd <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve Next Trip"
NotifyIcon1.ShowBalloonTip(500)
MessageBox.Show("Time to Reserve For Dec")
End If
End If
'NotifyIcon1.ShowBalloonTip(500)
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'read registry for date
' compare to todays date.
Dim Todayt As Date = Date.Now.ToString("MM/d/yyyy")
If My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing).length > 0 Then
MarchResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "March", Nothing)
Dim TDiffm = DateDiff(DateInterval.Day, Todayt, MarchResDate)
'Dim TDiffm As TimeSpan = MarchResDate.Subtract(Today)
'MessageBox.Show(TDiffm.Minutes.ToString)
If TDiffm <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve For March"
NotifyIcon1.ShowBalloonTip(500)
Timer1.Stop()
MessageBox.Show("Time to Reserve For March")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing).length > 0 Then
MayResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "May", Nothing)
Dim TDiffmay = DateDiff(DateInterval.Day, Todayt, MayResDate)
'Dim TDiffmay As TimeSpan = MayResDate.Subtract(Today)
'MessageBox.Show(TDiffmay.ToString)
If TDiffmay <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve For May"
NotifyIcon1.ShowBalloonTip(500)
Timer1.Stop()
MessageBox.Show("Time to Reserve For May")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing).length > 0 Then
JulyResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "July", Nothing)
Dim TDiffj = DateDiff(DateInterval.Day, Todayt, JulyResDate)
'Dim TDiffj As TimeSpan = JulyResDate.Subtract(Today)
'MessageBox.Show(Today.ToString & " - " & JulyResDate.ToString & " - " & TDiff.ToString)
If TDiffj <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve For July"
NotifyIcon1.ShowBalloonTip(500)
' Timer1.Stop()
MessageBox.Show("Time to Reserve For July")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing).length > 0 Then
SeptResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Sept", Nothing)
Dim TDiffs = DateDiff(DateInterval.Day, Todayt, SeptResDate)
'Dim TDiffs As TimeSpan = SeptResDate.Subtract(Today)
If TDiffs <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve For Sept"
NotifyIcon1.ShowBalloonTip(500)
Timer1.Stop()
MessageBox.Show("Time to Reserve For Sept")
End If
End If
If My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing).length > 0 Then
NewYearResDate = My.Computer.Registry.GetValue(baseKey & "\Camping", "Dec", Nothing)
Dim TDiffd = DateDiff(DateInterval.Day, Todayt, NewYearResDate)
'Dim TDiffd As TimeSpan = NewYearResDate.Subtract(Today)
If TDiffd <= 0 Then
NotifyIcon1.BalloonTipText = "Time to Reserve For Dec"
NotifyIcon1.ShowBalloonTip(500)
Timer1.Stop()
MessageBox.Show("Time to Reserve For Dec")
End If
End If
End Sub
-
Dec 6th, 2024, 10:42 AM
#4
Re: Systray icon sending notifications
You might need to consider using a https://learn.microsoft.com/en-us/do...m.timers.timer timer - I have a feeling a minimized form doesn't receive any Windows Messages and therefore a WinForms Timer isn't going to update... Although I could be completely wrong about this.
Then again the problem could be elsewhere, for starters with code like
Code:
Dim Todayt As Date = Date.Now.ToString("MM/d/yyyy")
You are converting a date, to a string, and back to a date and hoping that the conversion works - if you are after the date but not the time then this should work
Code:
Dim today As Date = Date.Today
I would also avoid DateDiff in VB.Net as this is just a hold over from VB6 and earlier, you can simply subtract one date from another to figure out how far apart they are.
-
Dec 6th, 2024, 11:19 AM
#5
Thread Starter
Frenzied Member
Re: Systray icon sending notifications
Thank you. I will update those piece of code. If a winform doesn't get windows messages, how does a icon in the systray able to send messages?
-
Dec 6th, 2024, 03:19 PM
#6
Re: Systray icon sending notifications
Originally Posted by phpman
Thank you. I will update those piece of code. If a winform doesn't get windows messages, how does a icon in the systray able to send messages?
It should still receive Timer_Tick messages when minimized
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 7th, 2024, 08:17 AM
#7
Thread Starter
Frenzied Member
Re: Systray icon sending notifications
Thanks for the info guys. I actually fixed my problem when adding the code to this thread. I had missed a variable that I had changed and didn't update it in all the checks and it was checking on an invalid date.
Code:
Dim TDiffm = DateDiff(DateInterval.Day, Todayt, MarchResDate)
I couldn't be for sure until this morning when the code ran for my test date. It did exactly as I was hoping for.
I also changed this line
Code:
Dim TDiffm = DateDiff(DateInterval.Day, Todayt, MarchResDate)
To this instead
Code:
Dim TDiffm As Integer = DateTime.Compare(MarchResDate, Todayt)
and took off the ToString on the date.now. I wasn't sure if it would compare correctly if not set in the correct format is the only reason I tried it that way. Thanks for the heads up.
-
Dec 7th, 2024, 08:32 AM
#8
Re: [RESOLVED] Systray icon sending notifications
I couldn't be for sure until this morning when the code ran for my test date. It did exactly as I was hoping for.
You know you can manually change your system clock? Just temporarily of course
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|