473,405 Members | 2,141 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,405 software developers and data experts.

Help getting the straight on .resources/Icon(Type, string) constructor

Greetings.

While trying to get a simple app working, I've been forced to delve into
embedded and/or linked resources a bit. I read all the reference for the
System.Resources namespace as well as all the material within the
"Resources and Localization..." tutorial. While I'm confident I now know
completely how to accomplish my original, simple task of embedding some
icons into my assembly and use of the same at runtime, I realize I've a
few unanswered questions on this topic.

Somehow, the docs for the System.Drawing.Icon class convinced me that I
should be able to very quickly extract an icon from a resource within my
assembly by merely using one of the classes overloaded constructors.
Specifically, the constructor taking two arguments: Icon(Type type,
string resource). According to the docs, this creates an instance from a
resource with the name specified by the string argument that is
contained within the assembly that contains the type specified by the
Type parameter.

After playing around a bit with how I *thought* this was supposed to
work I realize I just have no idea what I'm doing here. So, can anyone
give me some illumination or example as to how this Icon constructor is
intended to be used?

Thanks to anyone who chooses to humor me.
--
Kendall Gifford
========================================
WEB: http://kendall.jedis.com/
EMAIL: [REPLY TO NEWSGROUP PLEASE]
========================================

Nov 15 '05 #1
3 5628
Jon
When pass the Type, you are saying 'use the same assembly and namespace as this Type'.
It does not matter what kind of Type it is.

"Kendall Gifford" <re******@newsgroup.nospam> wrote in message news:%2****************@TK2MSFTNGP12.phx.gbl...
Greetings.

While trying to get a simple app working, I've been forced to delve into
embedded and/or linked resources a bit. I read all the reference for the
System.Resources namespace as well as all the material within the
"Resources and Localization..." tutorial. While I'm confident I now know
completely how to accomplish my original, simple task of embedding some
icons into my assembly and use of the same at runtime, I realize I've a
few unanswered questions on this topic.

Somehow, the docs for the System.Drawing.Icon class convinced me that I
should be able to very quickly extract an icon from a resource within my
assembly by merely using one of the classes overloaded constructors.
Specifically, the constructor taking two arguments: Icon(Type type,
string resource). According to the docs, this creates an instance from a
resource with the name specified by the string argument that is
contained within the assembly that contains the type specified by the
Type parameter.

After playing around a bit with how I *thought* this was supposed to
work I realize I just have no idea what I'm doing here. So, can anyone
give me some illumination or example as to how this Icon constructor is
intended to be used?

Thanks to anyone who chooses to humor me.
--
Kendall Gifford
========================================
WEB: http://kendall.jedis.com/
EMAIL: [REPLY TO NEWSGROUP PLEASE]
========================================

Nov 15 '05 #2
Jon wrote:
When pass the Type, you are saying 'use the same assembly and namespace as this Type'.
It does not matter what kind of Type it is.

From the caught exceptions, I see that it is indeed looking for my
resource in the namespace as the type argument:

"Resource 'AppIcon16x16_32' could not be found in class
'ZMA.Base.CExitForm'."

I guess I should be specific about what I was trying so you'll know
which of my misconceptions need fixed. I have a class inheriting from
Form that contains the following in InitializeComponent():

public class CExitForm : Form {
...
private void InitializeComponent() {
...
this.Icon = new System.Drawing.Icon(
this.GetType(),
"AppIcon16x16_32"
);
...
}
...
}

AppIcon16x16_32 is the name I gave one of my Icons as I put into a
resource file "Images.resources". Finally, I build the test app using
the following on the command line:
csc.exe /target:winexe /out:ZMA.exe

/res:Images.resources,ZMA.Base.Images Apptest.cs
(my csc.rsp provides all the /r[eferences])

When I run it, I get the System.ArgumentException from my call to the
Icon() constructor with the message described above.
**********

So, other than this I've tried various combinations naming my resource
(/res:Images.resources,[various combos]), I've tried linking to the
resource file instead of embedding it (/linkres:...) though I pretty
much knew this wasn't related to the problem, and I've tried different
values for the string argument of the Icon constructor.

Either I just keep missing the correct combination, or - more likely - I
am barking up the wrong tree. Thanks again for all help rendered.

--
Kendall Gifford
========================================
WEB: http://kendall.jedis.com/
EMAIL: [REPLY TO NEWSGROUP PLEASE]
========================================

Nov 15 '05 #3
Jon wrote:
Run ILDASM.
Check to see if 'AppIcon16x16_32' is indeed in the 'ZMA.Base' namespace.
It isn't. AppIcon16x16_32 isn't anywhere to be seen via ILDASM. The only
thing that ever shows up is either:
csc.exe ... /linkres:Images.resources,ZMA.Base.Images ..mresource public ZMA.Base.Images
{
.file Images.resources at 0x00000000
}

.... OR ...
csc.exe ... /res:Images.resources,ZMA.Base.Images

..mresource public ZMA.Base.Images
{
}

But even when I replace 'AppIcon16x16_32' with various strings like
'Images' or 'ZMA.Base.Images' or 'Images.resources' or even
'Images.AppIcon16x16_32' and other combinations, it doesn't seem to
work. Does anyone have a complete working example of using this constructor?

--
Kendall Gifford
========================================
WEB: http://kendall.jedis.com/
EMAIL: [REPLY TO NEWSGROUP PLEASE]
========================================

Nov 15 '05 #4

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

Similar topics

4
by: Laszlo Szijarto | last post by:
I'm iterating through various members of a struct using Reflection. While I can use fieldInfo.FieldType.BaseType to determine that a member is an array, how do I determine what that array is an...
2
by: Danny Gagne | last post by:
I'm currently working an .net application (I can use 1.1 or 2.0 if needed) that needs to read a wsdl file and generate another piece of code that can use it. I'm encountering a problem where I...
6
by: isaac2004 | last post by:
hello i am getting a type mismatch for a page i am trying to write. any help would be great source code <%@ Language=VBScript %> <% Option Explicit %> <!--#include...
8
by: marc | last post by:
hi there, i try to do a little generic style of programing in c#. the situation is like this: class MyObj1 { } class MyObj2 : MyClass1
6
by: Rico | last post by:
Hello, I'm looking for a way to reference the string name of an enumerator. I know in VB.net you can do "MyEnum.ToString" and get the name instead of the integer value. Is there a way I can do...
3
by: =?Utf-8?B?c3BkMzAwMQ==?= | last post by:
I have a C++/CLI app that uses a logging control in an ATL COM Server. C++ Interop seems to work just fine to pass data from the C++/CLI app to the ATL Control but I can't seem to figure out how...
0
by: j.lendholt | last post by:
Hey Folks, it's some years ago i wrote applications in VB respectively VB .NET 2003. We have a java-application based on java-scokets. We try to connect to the server, send up a string, let...
7
by: cephal0n | last post by:
Hi there! I've been racking my brains out for 4 days and still not getting why is msaccess stubborn about string parsing, first I have a table named tblItems, this table has columns: ProductItem,...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.