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?