对于那些正在寻找答案的人。事实证明,.NET Framework不支持在任务栏上显示进度条。Windows Forms也不支持此功能。它现在支持WPF。
然而,有一个解决方案。该解决方案由Ravikanth Chaganti编写。 https://www.ravichaganti.com/blog/programming-windows-7-taskbar-using-windows-api-code-pack-and-powershell/。要做到这一点,您需要下载和安装WindowsAPICodePack库(它是为Windows 7设计的)。:
打开PowerShell并加载程序集
[Reflection.Assembly]::LoadFrom(“D:\API\Microsoft.WindowsAPICodePack.Shell.Dll”)
创建TaskBarManager实例
$TaskBarObject = [Microsoft.WindowsAPICodePack.TaskBar.TaskBarManager]::Instance
设置ProgressBar状态
$TaskBarObject.SetProgressState(“Normal”)
这不是强制性的。但是,了解可能的值很重要。以下是每个进度条状态的含义:
无进度 - 不显示进度条 不确定 - 进度不确定(跑马灯) 正常 - 显示正常进度 错误 - 发生错误(红色) 暂停 - 操作已暂停(黄色)
要设置进度条值
$TaskBarObject.SetProgressValue(50,100)
# Add required assemblies
Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms, WindowsFormsIntegration
# Setup the XAML
[xml]$script:xaml = '<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Title="MyWindow" Height="240" Width="320" Background="Gray">
<Window.TaskbarItemInfo>
<TaskbarItemInfo/>
</Window.TaskbarItemInfo>
<Grid>
<Image Name="image" Height="64" Width="64"/>
</Grid>
</Window>'
# Create the form and set variables
$script:window = [Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xaml))
$xaml.SelectNodes("//*[@Name]") | ForEach-Object { Set-Variable -Name ($_.Name) -Value $window.FindName($_.Name) -Scope Script }
# This is the toolbar icon and description
$window.TaskbarItemInfo.Description = $window.Title
$window.TaskbarItemInfo.ProgressValue = 0.8
$window.TaskbarItemInfo.ProgressState = "Normal"
$window.ShowDialog()