Dot Net KB

Using C# To Extract Icons from any 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);


Download: IconExctractor.zip
2/25/2008 12:47:00 AM Published by FengLiN Category C Sharp(C#) Comments 0 Views (384)

People who read this, also read...


Name

Web site

Are you human? Enter the verify code below.

Comment