C # Windows 7 Taskbar Development progress bar (Progress bar)

Source: Internet
Author: User

The Windows 7 taskbar Adds a lot of other features to us: Jump Lists,window preview,progress bar,overlay Icon and more.

The functionality of the new taskbar makes our operations easier and faster, and Microsoft provides a handy tool for the Windows API Code Pack for. NET Framework to help us complete these developments, adding Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll.



When you use IE to download files, the taskbar icon synchronizes the current download progress (for example). So how do you achieve this in your application?



Taskbarmanager.setprogressvalue method

In the Taskbarmanager class, there are three different ways to use the Setprogressvalue method to set the current position of the progress bar, where CurrentValue is the parameter of the current position of the progress bar, MaximumValue is the maximum parameter:

//set current window public void setprogressvalue (int currentvalue, int maximumvalue) {    Corehelpers.throwifnotwin7 (); Taskbarlist.setprogressvalue (Ownerhandle, Convert.touint32 (currentvalue), Convert.touint3 2 (MaximumValue));} Sets the specified window public void setprogressvalue (int currentvalue, int maximumvalue, INTPTR windowhandle)    {corehelpers.throwifnotwin7 (); Taskbarlist.setprogressvalue (WindowHandle, Convert.touint32 (currentvalue), Convert.touint (MaximumValue));} Sets the specified WPF window public void setprogressvalue (int currentvalue, int maximumvalue, System.Windows.Wi    Ndow window) {corehelpers.throwifnotwin7 (); Taskbarlist.setprogressvalue (New Windowinterophelper (window)). Handle, Convert.touint32 (CurrentValue), Convert.touint32 (MaximumValue));} 
taskbarprogressbarstate progress bar Status

In addition to the common green (normal state), you can also use several other states by invoking enumeration Taskbarprogressbarstate, see the following table:

name Description
Noprogress Do not show progress bar
Indeterminate Indeterminate progress bar (in scroll state)
Normal Normal state (green)
Error Error status (red)
Paused Pause status (Yellow)

Taskbarmanager.setprogressstate Method

How do I set the above status for a progress bar? Of course Taskbarmanager also provides three different ways to use the Setprogressstate method to set the status of the progress bar accordingly:

Sets the current window status public void Setprogressstate (Taskbarprogressbarstate state) {    corehelpers.throwifnotwin7 ();    Taskbarlist.setprogressstate (Ownerhandle, (Tbpflag) state);} Sets the specified window state of public void Setprogressstate (Taskbarprogressbarstate, IntPtr windowhandle) {    Corehelpers.throwifnotwin7 ();    Taskbarlist.setprogressstate (WindowHandle, (Tbpflag) state);} Sets the specified WPF window state of public void Setprogressstate (taskbarprogressbarstate,                              System.Windows.Window window) {    Corehelpers.throwifnotwin7 ();    Taskbarlist.setprogressstate (        New Windowinterophelper (window)). Handle,        (Tbpflag) state);}

Effect Demo

        The following method can be used only in the program to achieve the control of the progress bar, the following code through the slider to adjust the current value of the progress bar:

<summary>///Initializing progress bar status///</summary>private void Initprogressstates () {    _ PROGRESSBARSTATUS.ITEMS.ADD (taskbarprogressbarstate.noprogress);    _progressbarstatus.items.add (taskbarprogressbarstate.indeterminate);    _progressbarstatus.items.add (taskbarprogressbarstate.normal);    _progressbarstatus.items.add (taskbarprogressbarstate.error);    _progressbarstatus.items.add (taskbarprogressbarstate.paused);    _progressbarstatus.selectedindex = 2;} <summary>///the progress bar value changes, change the taskbar progress and Status///</summary>private void _progressslider_valuechanged (object sender, EventArgs e) {    TaskbarManager.Instance.SetProgressValue (_progressslider.value, _progressslider.maximum );    TaskbarManager.Instance.SetProgressState ((taskbarprogressbarstate) _progressbarstatus.selecteditem);}

Normal State    Error Status paused State


C # Windows 7 Taskbar Development progress bar (Progress bar)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.