using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Bitmap FromIconToBitmap(Icon icon)
{
Bitmap bmp = new Bitmap(icon.Width, icon.Height);
using (Graphics gp = Graphics.FromImage(bmp))
{
gp.Clear(Color.Transparent);
gp.DrawIcon(icon, new Rectangle(0, 0, icon.Width, icon.Height));
}
return bmp;
}
private void Button1_Click(System.Object sender, System.EventArgs e)
{
Icon icon = WindowsFormsApplication1.Properties.Resources.Icon1;
pictureBox1.Image = FromIconToBitmap(icon);
}
}
}In this example, using the Bitmap class included in the System.Drawing namespace, an .ico file is converted to a .bmp file to display it in a PictureBox. This is necessary because the .ico format is not supported by the PictureBox control.
