如何获取与文件类型关联的图标?

时间:2021-06-23 05:54:45

I have a form that displays file information in a TabControl, and I'd like the pages to have the file's icon in their tab. How do I get the icon associated with a file type?

我有一个表单在TabControl中显示文件信息,我希望页面在其选项卡中有文件的图标。如何获取与文件类型关联的图标?

I'd prefer solutions that don't involve looking things up in the registry, but if that's the only way then so be it.

我更喜欢不涉及在注册表中查找内容的解决方案,但如果这是唯一的方式那么就是这样。

2 个解决方案

#1


12  

CodeProject has some classes you can download.

CodeProject有一些你可以下载的类。

First get the FileAssociationInfo, and from that get the ProgramAssociationInfo. The pai object can give you the icon.

首先获取FileAssociationInfo,然后从中获取ProgramAssociationInfo。 pai对象可以为您提供图标。

FileAssociationInfo fai = new FileAssociationInfo(".bob");
ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
ProgramIcon icon = pai.DefaultIcon;

#1


12  

CodeProject has some classes you can download.

CodeProject有一些你可以下载的类。

First get the FileAssociationInfo, and from that get the ProgramAssociationInfo. The pai object can give you the icon.

首先获取FileAssociationInfo,然后从中获取ProgramAssociationInfo。 pai对象可以为您提供图标。

FileAssociationInfo fai = new FileAssociationInfo(".bob");
ProgramAssociationInfo pai = new ProgramAssociationInfo(fai.ProgID);
ProgramIcon icon = pai.DefaultIcon;

#2