gpt4 book ai didi

c# - 如何调出内置文件复制对话框?

转载 作者:IT王子 更新时间:2023-10-29 04:49:31 26 4
gpt4 key购买 nike

我将使用我的 winforms 应用程序通过网络复制一个大文件,我需要显示某种进度条。我没有编写自己的复制例程,而是认为简单地显示内置文件复制对话框可能会更好。

我还需要“复制完成”和“复制失败”通知。

我需要它在 Windows XP、Vista 和 7 上工作。有没有办法从我的 C# 代码中调用以使用此功能?

最佳答案

答案取自:here

Windows Vista does indeed include a new copy engine that supports exactly what you're looking to do. However, it's possible that previously existing functionality may meet your needs. For example, if you want to copy, move, rename, or delete an individual file or directory, you can take advantage of SHFileOperation (exposed from shell32.dll), which is already wrapped by the Visual Basic® runtime. If you're using Visual Basic 2005, you can simply use functionality from the My namespace, for example:

 My.Computer.FileSystem.CopyDirectory(
sourcePath, destinationPath, UIOption.AllDialogs)

Accomplishing the same thing in C# involves only a little more work, adding a reference to Microsoft.VisualBasic.dll (from the Microsoft® .NET Framework installation directory) and using code such as the following:

using Microsoft.VisualBasic.FileIO;
...
FileSystem.CopyDirectory(
sourcePath, destinationPath, UIOption.AllDialogs);

When run, this will result in the same progress UI you'd see if you were doing the same file operations from Windows Explorer. In fact, when running on Windows Vista, you automatically get the new Window Vista progress UI, as shown in Figure 1. Dialog

关于c# - 如何调出内置文件复制对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6687443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com