【问题标题】:Task bar progress bar does not show after window was hidden隐藏窗口后任务栏进度条不显示
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2010-11-18
    • 2015-12-18
    • 2017-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多