How to display seconds in the system tray of the Windows 11 taskbar

Viewed 383

As we know, Microsoft choosed not to display seconds in Windows 11 system tray taskbar. Thus, I decided to create a little tool.

A simple timer and a label to show seconds next to the clock. The code I'm using is:


Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.Manual
        Me.Location = New Point(1891, 1029)
        Me.Size = New Size(21, 18)

        Me.TransparencyKey = Color.LightBlue
        Me.BackColor = Color.LightBlue
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label1.Text = ":" + Format(Now, "ss")
    End Sub
End Class

Always on top property is on true but if I click on the taskbar the form will disappear from there. Is there a way to fix it? thanks

2 Answers

It is disappearing because it is losing focus. If you want it to continuously keep focus or "refocus", you can introduce a hacky method that will refocus the form on each timer tick.

So you could try adding Me.Focus() to the timer1_tick event.

An example of this was shared on this SO post.

After a while, I decided to keep developing this little tool and for some reasons, the position of the form was moving up everytime there was a notification, so I end up forcing the position using the follow code inside of a System.Timers.Timer object that fires its Timer.Tick event every 0,1 seconds (100 milliseconds)

 Me.StartPosition = FormStartPosition.Manual
        Me.Location = New Point(1897, 1039)
        Me.Size = New Size(21, 18)
        Me.TransparencyKey = Color.LightBlue
        Me.BackColor = Color.LightBlue
        Label1.Text = Format(Now, "ss")
        Me.TopMost = True

Simple, but efficient.

Related