Extracting Icons from Files

by Amr 2/22/2008 12:25:00 AM

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)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Windows Forms

Related posts

Comments

2/24/2008 7:55:21 PM

Regev Porat

Cool!

Regev Porat il

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

5/16/2008 9:46:19 AM

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Amr Elsehemy Amr Elsehemy
MCSD, MCTS Sql 2005 E-mail me Send mail

Calendar

<<  May 2008  >>
MoTuWeThFrSaSu
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

View posts in large calendar

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Creative Commons
Sign in

Sitemeter