隐藏窗口后,任务栏进度条不显示

时间:2013-01-12 20:05:05

标签: c# windows-7 windows-api-code-pack

我正在尝试使用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();

关闭和打开进度条不起作用。

如何再次显示progressBar?

1 个答案:

答案 0 :(得分:1)

显然,TaskbarManager遇到了“this.ShowInTaskbar = false;”的问题。线。我刚删除它,因为隐藏窗口也会隐藏任务栏。但是,我需要保持“this.ShowInTaskbar = true;”。我只是假设它是一个错误。

相关问题