Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I added a picture box, when it is pressed, it opens the files and if you select a photo it shows that photo, but if you select a program it gives an error. If a program is selected, I want the program to show its icon.
They say type bitmap or something, but I haven't seen anyone explaining where to write what else to write.

What I have tried:

I use the following code:
C#
OpenFileDialog File2 = new OpenFileDialog();
            File2.Filter = "All files |";
            File2.ShowDialog();
            string FilePath2 = File2.FileName;
            pictureBox24.Image = Image.FromFile(FilePath2);
Posted
Updated 13-Dec-20 3:31am
v2

See this CodeProject article: Extract icons from EXE or DLL files[^]
 
Share this answer
 
The Image class can only create images from files that are in image format: JPG, BMP, PNG etc. Other file types will not work. If you want to display the icon of a file (and not all files contain icons) then you must use other libraries to extract them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900