Alex Rivera | Logout

Got .PNG file. Want embeddded icon resource displayed as icon on form title bar

Asked 2008-09-30T17:33:23.283
42

This was an interview question. Given Visual Studio 2008 and an icon saved as a .PNG file, they required the image as an embedded resource and to be used as the icon within the title bar of a form.

I'm looking for what would have been the model answer to this question, Both (working!) code and any Visual Studio tricks. (Model answer is one that should get me the job if I meet it next time around.)

Specifically I don't know how to load the image once it is an embedded resource nor how to get it as the icon for the title bar.

As a part solution, ignoring the embedded bit, I copied the resource to the ouput directory and tried the following:-

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.Icon = new Icon("Resources\\IconImage.png");
    }
}

This failed with the error "Argument 'picture' must be a picture that can be used as a Icon."

I presuming that the .PNG file actually needed to be a .ICO, but I couldn't see how to make the conversion. Is this presumption correct or is there a different issue?

Edit
Report

1 Answer

18

Go here:

http://www.getpaint.net/ (free)

And here:

Paint.NET ico Plugin (free)

Install Paint.NET. Put the ico plugin (second link) into the Paint.NET\FileTypes folder. Start up Paint.NET. Open your .png and save it as an .ico.

Free and easy.

answered 2010-03-18T18:57:17.277

Your Answer