简体   繁体   中英

How can I use the new Progress Control in .NET (as seen in the Windows File Transfer)?

Windows has an excellent control that shows both progress and rate of progress. It shows up in the 'more details' view of file copies, deletes, etc. For example:

表格上有进度控制

I do not want the file copy dialog box. I want the control inside it, for purposes other than a file copy. For example, video encoding progress.

Is it possible to use this control? I can't seem to find it anywhere and my search is frustrated by not knowing what precisely to call it! My final destination will be in C#/.NET.

The answer is probably, but you probably wouldn't want to use that exact control. The reason being that it's an OS control and thus subject to change without warning. Microsoft can patch that out next week if they want to (they won't most likely but still). You might want to look around and see if anyone is selling a control like that.

The alternative is using COM to trigger the shell to do the copy for you, which while annoying is supported and won't be patched out. It also has the benefit of being version independent.

Update:

The OP has made it very clear he is ONLY looking for the progress portion of the control and not a file copy . As such my recommendation on using the shell via COM is not valid. The best choice would be either to buy such a control... or worst case roll your own.

You could use the Microsoft.VisualBasic.Devices.Computer class.

using Microsoft.VisualBasic.Devices;

Computer comp = new Computer();
comp.FileSystem.CopyFile(sourceFileName, destinationFileName, UIOption.AllDialogs, UICancelOption.DoNothing);

You will need to add a reference to Microsoft.VisualBasic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM