The. NET winform program implements the glass effect and the taskbar progress bar effect in Windows 7.

Source: Internet
Author: User

Windows 7 provides many good user experiences, such as transparent form background, glass frosted effect, jumplist definition of the taskbar, and display the taskbar progress bar. With the appearance of these special effects, windows also provides the corresponding API support at the underlying layer, so that developers can easily apply them in their own applications as needed.Program. If you are a native C ++ follower, congratulations! You can use these Apis without any obstacles, provided that you need to read a huge development document. If you are a new student. NET developers. net developer is called a newbie. After all, it is better than C ++.) It does not matter. Microsoft also released a special windows7 API hosting class library on the msdn website, which is specially used in.. NET application. Let's take a look at the progress bar of the IE browser when downloading files in Windows 7. I believe many people are familiar with it. If you still have heard of it, either you are out or you have never followed these details of Windows 7.

To achieve this effect in your own. NET application, it is not enough to rely solely on the existing. Net class library. It must be supported by the Windows 7 API. ForCodeTo call the Windows 7 API, you can refer to an article on Microsoft msdn.Article, Http://archive.msdn.microsoft.com/windowsapicodepack. First, download and install windows_api_code_pack_self_extractor, which is actually a compressed package containing allSource codeAs well as a large number of examples, which can be found with documents. However, there are several prerequisites for using these class libraries:

1. the. NET Framework version must be 3.5sp1 or later.

2. The running environment must be Windows 7 RTM and its related versions. Some functions are available under Vista.

3. DirectX support is required.

The following is an effect implemented by using these class libraries, including transparent glass frosted form effects and display of the taskbar progress bar.

The implementation code is very simple, but the premise is that you reference the relevant class library of windowsapicodepack.

Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. LINQ;
Using System. text;
Using System. Windows. forms;
Using System. Threading;
Using Microsoft. windowsapicodepack. taskbar;
Using Microsoft. windowsapicodepack. shell;

NamespaceVerticalprogressbar
{
Public Partial ClassForm1: glassform
{
ProtectedBackgroundworker worker= Null;

Public Form1 ()
{
Initializecomponent ();
Worker =   New Backgroundworker ();
Worker. workerreportsprogress =   True ;
Worker. dowork + =   New Doworkeventhandler (worker_dowork );
Worker. progresschanged + =   New Progresschangedeventhandler (worker_progresschanged );
Worker. runworkercompleted + =   New Runworkercompletedeventhandler (worker_runworkercompleted );

Worker. runworkerasync ();
}

VoidWorker_runworkercompleted (ObjectSender, runworkercompletedeventargs E)
{
MessageBox. Show ("Complete!");
}

void worker_progresschanged ( Object sender, progresschangedeventargs e)
{< br> This . progressbar2.value = E. progresspercentage;

Taskbarmanager. instance. setprogressvalue (This. Progressbar2.value,This. Progressbar2.maximum );
}

Void Worker_dowork ( Object Sender, doworkeventargs E)
{
Int Count =   100 ;
For ( Int I =   0 ; I <= Count; I ++ )
{
Thread. Sleep ( 100 );
Worker. reportprogress (I );
}
}
}
}

Microsoft. windowsapicodepack. dll and Microsoft. windowsapicodepack. Shell. dll are introduced in the project. If you want the form to display a transparent glass matte effect, you must inherit the Form class from Microsoft. windowsapicodepack. Shell. glassform. In addition to updating the progressbar on the form, we also use taskbarmanager. instance. setprogressvalue to update the progress bar of the Windows taskbar.

With the support of this powerful hosting class library, you can easily call the windows7 API to achieve those cool effects. However, there is a small problem to solve. When you use this class library in your application and implement the desired effect in Windows 7, if the Windows environment you run is XP or 2003, your program will throw an exception, similar to the following.

In fact, in addition to functions related to Windows APIs, the program can continue to work. Therefore, you need to consider applications in different environments in the program. This is something you need to think about.

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.