locked
System Tray Icon RRS feed

  • Question

  • I am trying to create an icon in the system tray as status for num-lock, caps-lock, and scroll-lock, because my keyboard that came with my computer does not have status lights on the keyboard, and only on the system tray.

    The program however that came with it, does not like to work when I have some games open and stuff, it works usually in IE, and most other programs, but some programs just seem to interfere with it.

    I have made a new program on a 1 mili-second timer for the 3 and it seems to work just fine in the application, I was wondering now if I could move that over to the system tray and make it look like the one that came with computer, it has 3 different icons, and the icon changes for on/off and has a tooltip status change on mouse-over showing status of on/off.
    Tuesday, January 12, 2010 4:38 PM

Answers

  • Well, I got a code like this built now, except it might not be exactly what I need.

    Also, I did try setting the visible setting rather than all I did, except that creates false status update for some reason thinking that all the keys are always 'off'.

    Here is my code, does anyone see where I can make improvements?

    Public Class Form1
    
        Dim OldX
        Dim OldY
        Dim OldWidth
        Dim OldHeight
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            OldX = Location.X
            OldY = Location.Y
            OldWidth = Size.Width
            OldHeight = Size.Height
            FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Size = New Size(0, 0)
            Location = New Point(-124, -36)
            ShowInTaskbar = False
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            NotifyIcon3.Icon = Me.Icon
            NotifyIcon2.Icon = Me.Icon
            NotifyIcon1.Icon = Me.Icon
        End Sub
    
        Private Sub Icon_DoubleClicked()
            FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            Size = New Size(OldWidth, OldHeight)
            Location = New Point(OldX, OldY)
            ShowInTaskbar = True
        End Sub
    
        Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
            Icon_DoubleClicked()
        End Sub
    
        Private Sub NotifyIcon2_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon2.MouseDoubleClick
            Icon_DoubleClicked()
        End Sub
    
        Private Sub NotifyIcon3_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon3.MouseDoubleClick
            Icon_DoubleClicked()
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If My.Computer.Keyboard.NumLock Then
                NotifyIcon1.Text = "Num Lock On"
            Else
                NotifyIcon1.Text = "Num Lock Off"
            End If
            If My.Computer.Keyboard.CapsLock Then
                NotifyIcon2.Text = "Caps Lock On"
            Else
                NotifyIcon2.Text = "Caps Lock Off"
            End If
            If My.Computer.Keyboard.ScrollLock Then
                NotifyIcon3.Text = "Scroll Lock On"
            Else
                NotifyIcon3.Text = "Scroll Lock Off"
            End If
        End Sub
    
    End Class
    • Marked as answer by Maya Key Saturday, February 6, 2010 2:16 PM
    Tuesday, January 12, 2010 5:34 PM

All replies

  • Hi,

    Google is your friend http://www.google.com/search?q=.net+system+tray+application, you should try it sometime :o)

    Cheers

    Col
    Tuesday, January 12, 2010 4:59 PM
  • Well, I got a code like this built now, except it might not be exactly what I need.

    Also, I did try setting the visible setting rather than all I did, except that creates false status update for some reason thinking that all the keys are always 'off'.

    Here is my code, does anyone see where I can make improvements?

    Public Class Form1
    
        Dim OldX
        Dim OldY
        Dim OldWidth
        Dim OldHeight
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            OldX = Location.X
            OldY = Location.Y
            OldWidth = Size.Width
            OldHeight = Size.Height
            FormBorderStyle = Windows.Forms.FormBorderStyle.None
            Size = New Size(0, 0)
            Location = New Point(-124, -36)
            ShowInTaskbar = False
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            NotifyIcon3.Icon = Me.Icon
            NotifyIcon2.Icon = Me.Icon
            NotifyIcon1.Icon = Me.Icon
        End Sub
    
        Private Sub Icon_DoubleClicked()
            FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
            Size = New Size(OldWidth, OldHeight)
            Location = New Point(OldX, OldY)
            ShowInTaskbar = True
        End Sub
    
        Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
            Icon_DoubleClicked()
        End Sub
    
        Private Sub NotifyIcon2_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon2.MouseDoubleClick
            Icon_DoubleClicked()
        End Sub
    
        Private Sub NotifyIcon3_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon3.MouseDoubleClick
            Icon_DoubleClicked()
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If My.Computer.Keyboard.NumLock Then
                NotifyIcon1.Text = "Num Lock On"
            Else
                NotifyIcon1.Text = "Num Lock Off"
            End If
            If My.Computer.Keyboard.CapsLock Then
                NotifyIcon2.Text = "Caps Lock On"
            Else
                NotifyIcon2.Text = "Caps Lock Off"
            End If
            If My.Computer.Keyboard.ScrollLock Then
                NotifyIcon3.Text = "Scroll Lock On"
            Else
                NotifyIcon3.Text = "Scroll Lock Off"
            End If
        End Sub
    
    End Class
    • Marked as answer by Maya Key Saturday, February 6, 2010 2:16 PM
    Tuesday, January 12, 2010 5:34 PM
  • Oh, and of course I would be glad if someone could provide me some icons for those 3 being on/off, so it will be easier to tell rather than having to mouse-over each time.
    Tuesday, January 12, 2010 5:36 PM