How do I use embedded icon ?

  • Thread starter Thread starter Jack
  • Start date Start date
J

Jack

I was learning Windows programming in C# using Charles Petzold book,
but this book was written for the older version of .NET. The example
of using icon from embedded resource fails to work when executed step
by step following the book directions and I can't find what is wrong.
The executable throws an exception claiming that the resource cannot
be found.

The steps I'm taking are:

1) I created simple icon 32 x 32 16 colors file, named: iconfile.ico.
2) I added the icon file to the project using Add Existing Item ...
3) I changed build action to embedded resource for the added icon.
4) In the project options I changed DefaultNamespace to: Resource
5) In the Form1 constructor at the end I added the following line:

Icon = Icon(GetType(),"Resource.iconfile.ico");

6) I built the project (OK) and run it but it fails on the added
line of code with the mentioned exception.

What am I missing ?

Jack
 
Hi,

step 5 should read:

Icon someIcon = new Icon(Get...

you forgot the 'new' keyword.
Don't know if the other steps are correct, that's up to you.

Greetings,

Bram
 
Thanks for the obserwations, but this does not explains the problem.
First, I did forgot keyword "new" in the post on this group (step 5),
but not in the program.
Second, the "someicon" is also not required there. Notice, that the
step 5 is performed in the constructor of the main program Form and it
is an instance of the main window icon named "Icon", not the name of
the class. This is exactly how Petzolds book has that line coded
anyway. Besides, the code does compile but it raises exception clearly
stating, that the resource is not found during execution of this line
of code.
 
Back
Top