我正在尝试使用 C#(Net 3.5)向 Windows 7 中的任务栏图标添加进度条。我正在使用 Windows API 代码包来实现这一点:
if (WindowStateInternal == FormWindowState.Normal) // the taskbar can only be set if the window is visible
{
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
TaskbarManager.Instance.SetProgressValue(100 - (int)PercentRemaining, 100);
}
这工作正常,但只是第一次显示窗口。用户可以选择最小化窗口,然后将其删除,因为存在托盘图标。如果窗口再次显示,我无法再次打开进度条。
当用户最小化窗口时运行代码:
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
this.Visible = false; // otherwise problem when windows starts up and program is in autostart
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; // Hide from Task-List (Alt+Tab)
当它恢复正常时:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; // Show in Task-List (Alt+Tab)
this.Visible = true;
this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
this.BringWindowToFront();
关闭和打开进度条不起作用。
如何再次显示进度条?