0

I am trying to add a progress bar to the taskbar icon in Windows 7 with C# (Net 3.5). I am using the Windows API Code Pack to achieve this:

    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 works fine, but only the first time the window is displayed. The user has the option to minimize the windows which then will be removed, as a trayicon exists. If the window is displayed again, I can not turn on the progress bar again.

Code run when user minimized window:

    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)

and when it is coming back to normal:

    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();

Turning off and on the progressbar does not work.

How can I show the progressBar again?

Gunnar Bernstein
  • 6,074
  • 2
  • 45
  • 67
  • Have you tried inserting the code that you used to set the progress state of the progressbar in the section of code that displays the window once it is restored from the tray? (i.e. insert your first block of code after your third) – Brett Wolfington Jan 12 '13 at 20:18
  • That code is run every second by timer. The other code only when window size changed. – Gunnar Bernstein Jan 12 '13 at 20:27

1 Answers1

1

Apparantly the TaskbarManager has problems with the "this.ShowInTaskbar = false;" line. I just removed it, since hiding the window does hide the taskbar, too. However, I need to keep "this.ShowInTaskbar = true;". I just assume it is a bug.

Gunnar Bernstein
  • 6,074
  • 2
  • 45
  • 67