即使表单最小化,如何刷新任务栏预览
How to refresh taskbar preview even when the form is minimized
我遇到了问题,我注意到 90% 的 Windows(7,8,10) 应用程序不会更新任务栏预览(当您将鼠标悬停在应用程序上时,window任务栏中的图标),因此当应用程序最小化时,任务栏预览只会冻结并且不会更新,此外一些应用程序即使在最小化时也会更新它(例如 Windows Media Player、Music Bee)。我尝试使用 WindowsAPICodePack
自行解决此问题并裁剪任务栏预览,我还使用了第二种形式并将 Opacity
设置为 0 但它没有用。我现在没有任何代码可以显示。
以编程方式刷新任务栏预览并使用自定义位图:
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
Win7Api 示例的所有部分
我遇到了问题,我注意到 90% 的 Windows(7,8,10) 应用程序不会更新任务栏预览(当您将鼠标悬停在应用程序上时,window任务栏中的图标),因此当应用程序最小化时,任务栏预览只会冻结并且不会更新,此外一些应用程序即使在最小化时也会更新它(例如 Windows Media Player、Music Bee)。我尝试使用 WindowsAPICodePack
自行解决此问题并裁剪任务栏预览,我还使用了第二种形式并将 Opacity
设置为 0 但它没有用。我现在没有任何代码可以显示。
以编程方式刷新任务栏预览并使用自定义位图:
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
Win7Api 示例的所有部分