When you copy a large file in Explorer, you see the standard Windows progress dialog coming up with "flying papers" animation with the calculation of estimated time remaining. This dialog is accessible to any Windows application through IProgressDialog interface. While this interface is pretty simple and intuitive to use, more often than not, many developers are unaware of its existence spending lot of time in replicating exactly the same functionality. The goal of this article is to create awareness about this interface and to provide an even simpler managed .NET wrapper to use this functionality.
The current article is based on another article on using
IProgressDialog in VB6 at msjogren.com. The current article uses the same .TLB file as in that article to create the managed .NET wrapper and adds-on few little extras such as additional animation styles.
Using the code
Warning: There is a default two second delay before the dialog appears. This seems to be default behavior.
Using the code is pretty easy as can be seen in the following snippet:
Dim progressDialog As New WinProgressDialog.ProgressDialog
progressDialog.Show(Me.Handle.ToInt32, "descr1", "Descr2", MaxValue)
You might want to check the return value to see if the user has pressed the Cancel button. This you can also check by calling
Many times, you just want to show an animation without progress dialog (like showing flashlight when performing search). You can do this by setting
Points Of Interests
Notice the use of
FreeLibrary to get the handle of standard animations from shell32.dll. It's possible to use your own custom animation instead of standard ones available through
Dispose is required to make sure a call to
FreeLibrary was made and also to
Marshal.ReleaseComObject on main dialog.
The Interop.VBProgressDialog.dll which is referenced by the project is automatically generated by VS.NET when progdlg.tlb is referenced. If you need to sign the DLL, then you will need to manually generate a signed version of interop using tlbimp.