Taskbar Icon doesn't match Application Icon when using a Soortcut

Devon Nullman 20 Reputation points
2025-01-19T16:45:52.3333333+00:00

I wrote a program that monitors my Documents Folder and every time a file that matches my criteria is saved, it makes a copy in the selected backup folder. I added code that blinks the Icon a few times so I know that the file was backed up. The blinking is done using a timer that changes the icon from "1.ico" to "2.ico" and back a few times. I don't know if the problem is related to Visual Studio or what but once the app is built, starting it directly is fine but making a shortcut and opening the app from it makes the tray icon a generic one and the blinking does not happen. Changing the shortcut icon manually to match the app icon makes it look fine but there is no blinking, The timer code is quite simple:

Private Sub IconBlink_Tick(sender As Object, e As EventArgs) Handles IcoBlink.Tick

Ticks += 1

If Ticks Mod 2 = 0 Then

Me.Icon = Icon2

Else

Me.Icon = Icon1

End If

If Ticks >= 10 Then

IcoBlink.Stop()

Me.Icon = Icon1

End If

End Sub

Any ideas?

Icon1

That is "Icon1" - "Icon2" is identical except it is dark grey

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,768 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RLWA32 46,566 Reputation points
    2025-01-19T19:48:38.6533333+00:00

    Instead of changing icons you can use the Windows API FlashWindowEx function to flash your application's taskbar button.

    For example, in a Windows Forms Application -

    FlashButton

    Example code -

    Public Class Form1
        Public FW_TRAY As Integer = 2
        Public FW_TIMER As Integer = 4
        Public FW_STOP As Integer = 0
        <StructLayout(LayoutKind.Sequential)>
        Public Structure FLASHWINFO
            Public cbSize As Integer
            Public hwnd As IntPtr
            Public flags As Integer
            Public count As Integer
            Public timeout As Integer
        End Structure
        <DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, ExactSpelling:=True)>
        Public Shared Function FlashWindowEx(fwi As FLASHWINFO) As Boolean
        End Function
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim fwinfo As FLASHWINFO = New FLASHWINFO()
            fwinfo.cbSize = Marshal.SizeOf(Of FLASHWINFO)
            fwinfo.hwnd = Handle
            fwinfo.flags = FW_TRAY
            fwinfo.timeout = 1000
            fwinfo.count = 10
            FlashWindowEx(fwinfo)
        End Sub
    
    End Class
    

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.