473,396 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I use embedded icon ?

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
Nov 15 '05 #1
2 7316
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

"Jack" <ma*****@comcast.net> wrote in message
news:a7***********************@posting.google.com. ..
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

Nov 15 '05 #2
"Bram" <bv*****@nospam.skynet.be> wrote in message news:<40*********************@news.skynet.be>...

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.
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

"Jack" <ma*****@comcast.net> wrote in message
news:a7***********************@posting.google.com. ..
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

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: carl.manaster | last post by:
Hi, In <http://groups-beta.google.com/group/microsoft.public.dotnet.languages.csharp/msg/05abaf8460c61859>, back in 2003, "SleazySt" wrote that > Unfortunately, C# projects can't have...
8
by: Wayne Hoover | last post by:
I have an embedded icon resource in my project - I need to reference this icon for a grid cell. I've tried using the following but it does not work. Any help appreciated: Dim im As...
8
by: news.microsoft.com | last post by:
I have an icon that I can reference by the following: Dim im As System.Drawing.Image im = im.FromFile(lsapppath & "ChkMrk.ico") g_mainform.fg.SetCellImage(g_mainform.FG.Row, 5, im) The problem...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.