Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / February 2005

Tip: Looking for answers? Try searching our database.

Problems Adding Icons to ImageList

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flynn Arrowstarr - 16 Feb 2005 18:39 GMT
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 we can't corrupt the youth of today,
the adults of tomorrow won't be any fun.
Daniel Moth - 19 Feb 2005 01:35 GMT
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
--
http://www.danielmoth.com/Blog/

> Hi, everyone.
>
[quoted text clipped - 67 lines]
> If we can't corrupt the youth of today,
> the adults of tomorrow won't be any fun.
Flynn Arrowstarr - 20 Feb 2005 01:25 GMT
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

> 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
[quoted text clipped - 81 lines]
> > If we can't corrupt the youth of today,
> > the adults of tomorrow won't be any fun.
Daniel Moth - 20 Feb 2005 10:52 GMT
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/

> Hi, Daniel.
>
[quoted text clipped - 112 lines]
>> > If we can't corrupt the youth of today,
>> > the adults of tomorrow won't be any fun.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.