Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to show exe icon to picturebox c#

What I have tried:

how to show exe icon to picturebox c#
Posted
Updated 9-Dec-20 23:18pm

You can get an Icon instance of said icon using Icon.ExtractAssociatedIcon[^], with the file path of the executable as argument (if it's your own executable, this file path is in Assembly.GetExecutingAssembly().Location with Assembly in System.Reflection).

To put it in the PictureBox, you'll have to convert it to a Bitmap using Bitmap.FromHicon[^] (usage: Bitmap.FromHicon(yourIcon.Handle) where yourIcon is the result of ExtractAssociatedIcon).
 
Share this answer
 
Comments
Member 14013003 5-Jan-20 7:59am    
thanks worked <3
If I click the picture box, I open the files and if you select the photo, it happens. When I choose google chrome it does not work. I use the following code.

OpenFileDialog dosya2 = new OpenFileDialog();
dosya2.Filter = "All files|";
dosya2.ShowDialog();
string DosyaYolu2 = dosya2.FileName;
PictureBox1.Image = DosyaYolu2;
 
Share this answer
 
Comments
CHill60 10-Dec-20 6:38am    
If you have a question then use the red "Ask a Question" link at the top of this page. Alternatively, you could comment on Solution 1 by using the "Have a Question or Comment?" link next to it.
Either way, do not post questions nor comments as a "Solution" to another post
Member 15017377 12-Dec-20 10:03am    
I just discovered the site, I did not know, I apologize and I expect your help for questions
Richard MacCutchan 10-Dec-20 6:55am    
Because you are passing a string (the filename) to the PictureBox, instead of the contents of the file. To do it correctly see PictureBox.Image Property (System.Windows.Forms) | Microsoft Docs[^].
Member 15017377 13-Dec-20 8:55am    
I did not understand the microsoft site when I looked PictureBox1.Image = FilePath2; how do i do instead of this code
Richard MacCutchan 13-Dec-20 9:15am    
You cannot pass a string to a PictureBox, it has no meaning. You must create a valid Image object from the file which you then pass to the PictureBox for rendering to the display. Look at the documentation for the Image class to see how to do it.

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