An implementation of Visual Basic that is built into Microsoft products.
Thank you for reaching out. This behavior is the known edge case in windows 11 where the shells taskbar rendering engine struggles to sink dynamically set icons (via Me.icon) with the overflow manager. When a WinForms application is pushed to the boundary of the “three dots” (…) overflow area the taskbar occasionally fails to pull the windows specific icon and instead falls back to the default icon embedded in the executables resource.
The root cause
the issue occurs because Me.Icon only changes the icon for that specific window instance. Windows 11 taskbar particularly when handling overflow frequently queries the process/executable level icon or the AppUserModelID cache. If the executable does not have a high resolution I can embed it at index 0 or if the OS has not cached the icon for that specific task bar slot it reverts to the generic “EXE” icon.
Recommended solutions
- set the application level icon (primary fix) instead of relying solely on code to change the icon at runtime you must embed the icon into the project properties. This ensures that the window shell has a permanent reference to the icon even when the form is not fully “active” in the overflow calculations.
- In Visual Studio right click your project> properties
- go to application tab
- under resources locate the icon drop down and browse to your .ico file.
- Rebuild your solution this embeds the icon as resource ID 0 which is what the taskbar prefers.
- Implementation via Win32 API(if runtime changes are required) if you must set the icon via code(e.g., if the icon changes based on user state,) using Me.Icon is sometimes “too late” for the shell. You can use the send message API to explicitly tell the window shell to update both the small and big icons for the window handle.
Imports System.Runtime.InteropServices Public Class Form1 <DllImport("user32.dll", CharSet:=CharSet.Auto)> Private Shared Function Send Message (ByVal hWnd As intPtr, ByVal Mg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr End function Private Const WM_Seticon As integer = &H80 Private Const ICON_SMALL As integer = 0 Private Const Icon_BIG As Integer = 1 Private Sub Forml_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try Dim newIcon As New Icon("C:\Path\To\Your\Icon.ico") Me.Icon = newIcon ' Force the Shell to recognise the new icon handles SendMessage(Me.Handle, WM_SETICON, New IntPtr(ICON_SMALL),newIcon.Handle) SendMessage(Me.Handle, WM_SETICON, New IntPtr(ICON_BIG),newIcon.Handle) Catch ex As exception MsgBox(ex.Message) End Try End Sub End Class - Verification of icon formats windows 11 is stricter with DPI scaling. Ensure your .ico file contains the following sizes:
- 16x16, 24x24, 32x32, 48x48 and 256x256 (PMG compressed)
Please let us know if you require any further assistance we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".