Extracting Icons from files.

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);
}

 

Attachment: IconExctractor.zip
Published Sunday, May 20, 2007 1:30 PM by amrelsehemy
Filed under:

Comments

No Comments