0

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

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

如何再次显示进度条?

4

1 回答 1

1

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

于 2013-01-12T21:58:52.190 回答