C# 中的简单文件和文件夹视图

发布于 2024-08-26 02:59:40 字数 235 浏览 1 评论 0原文

我最近看到一个应用程序有两个简单的控件(一个树视图和一个详细的列表视图),用于列出目录和文件。我知道如何做到这一点,但除了列出文件之外,它还有另一个不错的功能:它从系统 shell 加载信息,例如文件夹图标、文件规范(主要是文件类型,从系统继承,所以如果我有一个应用程序什么将 SVG 文件类型修改为“未知矢量图形内容”,然后它显示所有 SVG 文件的类型为之前的该字符串)。

我想请问您,如何在不使用任何第三方库的情况下轻松实现这些功能?

I have seen an application recently what had two simple controls (a treeView and a detailed ListView) what were used for listing directories and files. I know how to do this, but it had another nice feature other than listing files: it loaded info from the system shell, like icons of folders, file specifications (file types mostly, inherited from the system, so if I had an application what modified the SVG file type to "Unknown vectorgraphic stuff" then it showed all SVG file's type as this string before).

I would like to ask You, that how could I make these features easily without using any third party library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漫雪独思 2024-09-02 02:59:40
  1. 要获取文件图标,请使用System.Drawing.Icon.ExtractAssociatedIcon
  2. 要获取文件类型,您需要使用Win32 SHGetFileInfo函数。
  3. 要获取修改日期、文件大小等,您可以使用 DirectoryInfoFileInfo 类。

您还可以考虑使用现成的控件,例如 Shell MegaPack,它显示这样的文件/文件夹相同的图标、细节、菜单等

  1. To get the file icon, use System.Drawing.Icon.ExtractAssociatedIcon.
  2. To get the file type, you need to use the Win32 SHGetFileInfo function.
  3. To get date modified, file size, etc, you can use DirectoryInfo and FileInfo classes.

You can also consider using ready-made controls like Shell MegaPack which show files/folders like this with same icons, details, menus, etc

夏尔 2024-09-02 02:59:40

您可以通过 System.Drawing.Icon.ExtractAssociatedIcon() 获取文件的图标...

you can get icon for a file by System.Drawing.Icon.ExtractAssociatedIcon()...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文