Extracting Icons from Files

Update: This approach is only to show one of the hidden gems in the .net framework and not to steal copyrighted icons.
Icons of other programs should only be used after owner approval.

Have you ever seen a file with a pretty icon you wanted to use but you couldn't get a similar one in your program?

If yes,  try this method >> Icon.ExtractAssociatedIcon here is the code I wrote that works fine, you will also find the sample attached


Icon ico;

public Form1()
  ico = this.Icon;

private void btnGetIcon_Click(object sender, EventArgs e)
  if(dlgOpen.ShowDialog() == DialogResult.OK)
    ico = Icon.ExtractAssociatedIcon(dlgOpen.FileName);
    this.Icon = ico;

private void pnlIcon_Paint(object sender, PaintEventArgs e)
  e.Graphics.DrawIcon(ico, pnlIcon.ClientRectangle);


IconExtractor.zip (7.03 kb)







3 responses to “Extracting Icons from Files”

  1. Bob Saggett Avatar
    Bob Saggett

    Have you ever seen a file with a pretty icon you wanted to use but you couldn’t get a similar one in your program? Do you think that other artists are simply to be copied, regardless of the hours of work that they put in to create the icon? Is copyright law just a scam to protect big industrial players and not to protect the little guys too?

    Answer YES to all three? Well, go ahead and rip off my work, thanks.

  2. Amr Avatar

    @Bob Saggett
    No, Ofcourse the post has been updated due to your comment, thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *