Extracting Icons from Files

by Amr Elsehemy 21. February 2008 15:25

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()
{
  InitializeComponent();
  ico = this.Icon;
}

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

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

IconExtractor.zip (7.03 kb)

Tags: ,

Windows Forms

Comments

2/24/2008 10:55:21 AM #

Regev Porat

Cool!

Regev Porat Israel |

9/3/2008 11:23:34 AM #

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.

Bob Saggett United States |

9/3/2008 11:38:30 AM #

Amr

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

Amr Egypt |

Comments are closed

About the author

Amr Elsehemy
MCSD C#.Net,
MCTS Sql 2005,
MCPD Enterprise
avatar
E-mail me Send mail

Calendar

<<  March 2010  >>
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar