【发布时间】:2012-12-27 04:09:02
【问题描述】:
我正在尝试使用 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();
关闭和打开进度条不起作用。
如何再次显示进度条?
【问题讨论】:
-
您是否尝试在从托盘恢复后显示窗口的代码部分中插入用于设置进度条进度状态的代码? (即在您的第三个代码块之后插入您的第一个代码块)
-
该代码由计时器每秒运行一次。其他代码仅在窗口大小更改时。
标签: c# windows-7 windows-api-code-pack