.netvb.nettaskbarwindows-media-playerwindows-api-code-pack

How to refresh taskbar preview even when the form is minimized


I'm having a problem and I noticed 90% of Windows(7,8,10) applications don't update taskbar preview (that little window when you hover over an app icon in taskbar) so when the app is minimized the taskbar preview just freezes and don't update besides some apps do update it even when minimized (e.g. Windows Media Player, Music Bee). I tried to fix this issue myself using WindowsAPICodePack and cropped the taskbar preview and I also used a second form and set the Opacity to 0 but it didn't work. I don't have any code to show right now.


Solution

  • To refresh the taskbar preview programmatically and use custom bitmaps:

        Imports System
    Imports System.Drawing
    Imports System.Threading
    Imports System.Windows.Forms
    Imports Microsoft.WindowsAPICodePack.Taskbar
    
    Namespace CustomThumbnailImage
        Public Partial Class Form1
            Inherits Form
    
            Private customThumbnail As TabbedThumbnail
    
            Public Sub New()
                InitializeComponent()
            End Sub
    
            Protected Overrides Sub OnShown(ByVal e As EventArgs)
                MyBase.OnShown(e)
                customThumbnail = New TabbedThumbnail(Me.Handle, Me.Handle)
                TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(customThumbnail)
                customThumbnail.TabbedThumbnailBitmapRequested += AddressOf customThumbnail_TabbedThumbnailBitmapRequested
            End Sub
    
            Private Function GenerateBitmap() As Bitmap
                Dim bitmap As Bitmap = New Bitmap(150, 150)
    
                Using g = Graphics.FromImage(bitmap)
                    Dim random = New Random(Environment.TickCount)
    
                    Using brush = New SolidBrush(Color.FromArgb(255, random.[Next](255), random.[Next](255), random.[Next](255)))
                        g.FillEllipse(brush, 10, 30, 130, 90)
                    End Using
                End Using
    
                Return bitmap
            End Function
    
            Private Sub customThumbnail_TabbedThumbnailBitmapRequested(ByVal sender As Object, ByVal e As TabbedThumbnailBitmapRequestedEventArgs)
                Dim bitmap = GenerateBitmap()
                customThumbnail.SetImage(bitmap)
                ThreadPool.QueueUserWorkItem(Sub(c)
                                                 Thread.Sleep(2000)
                                                 Me.Invoke(New MethodInvoker(AddressOf InvalidateThumbnail))
                                             End Sub)
            End Sub
    
            Private Sub InvalidateThumbnail()
                customThumbnail.InvalidatePreview()
            End Sub
        End Class 
    End Namespace
    

    All part of the Win7Api Samples