简体   繁体   English

如何使用.NET在Windows窗体中显示Windows文件夹内容?

[英]how to show a windows folder contents in a windows form using .NET?

我想在我的Windows窗体中显示文件夹内容,用户可以从中复制粘贴用户所需的文件,我必须使用哪种类型的容器?

Basically you have two options. 基本上你有两个选择。 You can get an already build control and use it in your application, there are lots of them but not very good and you'll have to pay for one. 你可以获得一个已经构建的控件并在你的应用程序中使用它,有很多但不是很好,你需要支付一个。

Or you could use a TreeView / ListView and build your own control that will suite best what you need. 或者您可以使用TreeView / ListView并构建自己的控件,以满足您的需求。 Here is an example explained and with source code. 这是一个解释的示例和源代码。

另一种方法是你可以获得Windows API代码包 ,其中包含实际资源管理器shell控件的托管包装器,它基本上允许您直接在应用程序中嵌入资源管理器。

在我使用Ultra win树(infrajestics控制)在树视图中查看所有文件之前。

考虑使用Shell MegaPack中的FolderView和FileView控件。

Assuming : 假设 :

  1. the design requirements prohibit showing the actual location of the files the end-user can copy or paste. 设计要求禁止显示最终用户可以复制或粘贴的文件的实际位置。 Assume all file names shown are stripped of their path locations. 假设显示的所有文件名都被删除了它们的路径位置。

  2. the list of files is "flat" (no treeview type display is needed) 文件列表是“平”(不需要树视图类型显示)

  3. there's a need to move, or copy, one or more files from an original "complete" list to another "partial list" 需要将一个或多个文件从原始“完整”列表移动或复制到另一个“部分列表”

I'd create an interface with two ListViews in a Panel : one column per ListView wide enough to display file names : allow multi-select in both of them. 我在Panel中创建了一个带有两个ListView的接口:每个ListView一列足以显示文件名:允许在两个列中进行多选。

I'd either implement drag-and-drop using standard techniques, or, more likely, I'd create a set of buttons with arrows to move items back and forth between the ListViews. 我要么使用标准技术实现拖放,要么更有可能的是,我创建了一组带箭头的按钮,以便在ListView之间来回移动项目。 I might have seperate delete buttons for each ListView and require the end-user to confirm deletion depending on the application. 我可能会为每个ListView分别删除按钮,并要求最终用户根据应用程序确认删除。

If "multiple copies" (more than one list entry with identical content) are allowed I would probably use some keyboard options to control this, particularly if I were drag/dropping. 如果允许“多个副本”(多个具有相同内容的列表条目),我可能会使用一些键盘选项来控制它,特别是如果我是拖放。

Depending on the application, I'd think about letting the end-user make "snapshots" of the current state of the two ListViews, which could then be "restored" : while a simple "Cancel" button could take care of the case where you want to reset the whole thing. 根据应用程序的不同,我会考虑让最终用户对两个ListView的当前状态进行“快照”,然后可以“恢复”:而简单的“取消”按钮可以处理这种情况。你想要重置整个事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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