How do I get the icon associated with a file type?

吃可爱长大的小学妹 提交于 2019-11-26 16:37:46

问题


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?

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.


回答1:


CodeProject has some classes you can download.

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

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



回答2:


System.Drawing.Icon.ExtractAssociatedIcon(string filePath)



来源:https://stackoverflow.com/questions/272035/how-do-i-get-the-icon-associated-with-a-file-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!