I’m making a explorer like app to browse files stored on my computer. My app will be in “Icon” view. The question is: How to display the icon of an exe file?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are several ways to do that. The easiest is probably to add a reference to
System.Drawingand take advantage of theIcon.ExtractAssociatedIconmethod:Another option, if you don’t want to use
System.Drawing, is to obtain the icon from theSHGetFileInfoAPI. It’s more difficult, but also much more flexible; for instance you can get the icon of a file that doesn’t exist, based on the extension (of course for an executable it’s not very useful, since it would return the default icon for executable files).Another advantage of this approach is that it can also get the icon for a directory (see last edit in the code), which isn’t possible with
Icon.ExtractAssociatedIcon