Problems Adding Icons to ImageList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, everyone.

I'm trying to add an Icon to an ImageList control. I've set the icons to
Embedded Resource, and I'm following the steps listed in a post from Neville
Lang in November (thread about adding images to toolbars on an HP 47xx).

| i) Use .ICO files in the project (instead of BMP files)
| and set their Build Action to Embedded Resource
| ii) Changed my method call to:
|
| ImageList.Images.Add(new
| Icon(Assembly.GetExecutingAssembly().
| GetManifestResourceStream("MyProject.tb
| Image1.ico")))
|
| As stated in my earlier post, the above call(s) needs to be moved out of
| InitializeComponent() and placed after the InitializeComponent().
|

I'm trying to do something similar to this where I've moved the code to
create the Icon resource to a private function called GetIcon.

private Icon GetIcon(string name)
{
// Get the current assembly and open a stream to the icon file
Assembly execAssembly = Assembly.GetExecutingAssembly();
try
{
Stream fileStream = execAssembly.GetManifestResourceStream
(execAssembly.GetName().Name + "." + name + ".ico");

// Create and return the icon
Icon icon = new Icon(execAssembly.GetManifestResourceStream
(execAssembly.GetName().Name + "." + name + ".ico"));
}
catch(ArgumentException ex)
{
MessageBox.Show("Argument Exception: " + ex.Message +
"\n" + execAssembly.GetName().Name + "." + name + ".ico");
}
catch(Exception ex)
{
MessageBox.Show("System Exception: " + ex.Message);
}
return icon;
} // end Icon GetIcon(string icon)

I'm getting an Argument Exception when I try to run this code. In checking a
similar piece of code on the OpenNetCF forums, I found it doesn't like
assemblies with spaces in their names. However, I don't have a space in my
assembly name. Any ideas why this wouldn't work?

I've tried making the call to GetIcon in the ctor for formMain and in the
formMain_Load event. I get the same error each time. Here's the method call
I'm using:

this.imagelistMain.Images.Add(GetIcon("normal"));

My device is an Axim X3 with NetCF SP 3. I'm running into the problem on
both the emulator (also with SP3) and the device. Thanks for any help you can
provide. Please let me know if there's any other information you need from me.

Flynn
 
If you break some of those long lines into smaller statements you could tell
us which method throws the ArgumentException e.g. too many method calls on
this line:
Icon icon = new
Icon(execAssembly.GetManifestResourceStream(execAssembly.GetName().Name +
"." + name + ".ico"));

Anyway, Get..Stream is case sensitive; have you tried it with .ICO instead?

Cheers
Daniel
 
Hi, Daniel.

The line that is throwing the exception is this one:

Icon icon = new Icon(execAssembly.GetManifestResourceStream
(execAssembly.GetName().Name + "." + name + ".ico"));

I'm trying to add an icon called "normal.ico" to the ImageList. To do this,
I call the GetIcon routine and pass it the name of the icon (without the
extension). The icon file is an Embedded Resource. So, I'm using
GetName().Name to provide the name of the assembly, and appending the name of
the icon file and the extension.

Thanks again for any help you can provide. =)

Flynn

Daniel Moth said:
If you break some of those long lines into smaller statements you could tell
us which method throws the ArgumentException e.g. too many method calls on
this line:
Icon icon = new
Icon(execAssembly.GetManifestResourceStream(execAssembly.GetName().Name +
"." + name + ".ico"));

Anyway, Get..Stream is case sensitive; have you tried it with .ICO instead?

Cheers
Daniel
 
You have confirmed the line but you still have not broken it down, have you?

Anyway... what happened when you changed ".ico" to ".ICO" like I suggested?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Flynn Arrowstarr said:
Hi, Daniel.

The line that is throwing the exception is this one:

Icon icon = new Icon(execAssembly.GetManifestResourceStream
(execAssembly.GetName().Name + "." + name + ".ico"));

I'm trying to add an icon called "normal.ico" to the ImageList. To do
this,
I call the GetIcon routine and pass it the name of the icon (without the
extension). The icon file is an Embedded Resource. So, I'm using
GetName().Name to provide the name of the assembly, and appending the name
of
the icon file and the extension.

Thanks again for any help you can provide. =)

Flynn
 
Back
Top