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

本文关键字:显示 任务栏 窗口 隐藏 | 更新日期: 2023-09-27 17:52:46

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

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

如何再次显示进度条?

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

显然任务栏管理器与"this "有问题。ShowInTaskbar = false;" line。我只是删除了它,因为隐藏窗口也隐藏了任务栏。然而,我需要保留"这个"。ShowInTaskbar = true;