473,414 Members | 1,567 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,414 software developers and data experts.

How load icon from embeded resource into imageList?

I have been searching for how to get an icon resource and load it into an
ImageList. I added an *.ico file to my project and set the files "Build
Action" to "Embedded Resource". Is there any easy way to do this? This was
easy to do in the old MFC. I can not find the answer in C#.

I also need to embed an XML file into the resource and load it at run time.
I am hoping once I figure out how to load an icon resource then loading an
XML file will be similar.

Thanks in advance for any tips or suggestions,

-Ed


Nov 15 '05 #1
4 48939
This is a call to get the bitmap. the funciton is below:

picStop.Image = GetImage(ImageName.StopDisabled);

private Bitmap GetImage(ImageName i)

{

switch(i){

case ImageName.RecordDisabled:

return new
Bitmap(System.Reflection.Assembly.GetExecutingAsse mbly().GetManifestResource
Stream("C_SharpPDA.DictateDis.jpg"));
case ImageName.RecordEnabled:

return new
Bitmap(System.Reflection.Assembly.GetExecutingAsse mbly().GetManifestResource
Stream("C_SharpPDA.dictate.jpg"));
case ImageName.Recording:

return new
Bitmap(System.Reflection.Assembly.GetExecutingAsse mbly().GetManifestResource
Stream("C_SharpPDA.dictate.jpg"));

case ImageName.PlayEnabled:

return new
Bitmap(System.Reflection.Assembly.GetCallingAssemb ly().GetManifestResourceSt
ream("C_SharpPDA.play.jpg"));

case ImageName.PlayDisabled :

return new
Bitmap(System.Reflection.Assembly.GetCallingAssemb ly().GetManifestResourceSt
ream("C_SharpPDA.playinverted.jpg"));

case ImageName.StopDisabled :

return new
Bitmap(System.Reflection.Assembly.GetCallingAssemb ly().GetManifestResourceSt
ream("C_SharpPDA.stopdisabled.jpg"));

case ImageName.StopEnabled:

return new
Bitmap(System.Reflection.Assembly.GetCallingAssemb ly().GetManifestResourceSt
ream("C_SharpPDA.stop.jpg"));

}
return new
Bitmap(System.Reflection.Assembly.GetExecutingAsse mbly().GetManifestResource
Stream("C_SharpPDA.dictate.jpg"));

}

"Ed Sutton" <no****************@nomadics.com> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
I have been searching for how to get an icon resource and load it into an
ImageList. I added an *.ico file to my project and set the files "Build
Action" to "Embedded Resource". Is there any easy way to do this? This was easy to do in the old MFC. I can not find the answer in C#.

I also need to embed an XML file into the resource and load it at run time. I am hoping once I figure out how to load an icon resource then loading an
XML file will be similar.

Thanks in advance for any tips or suggestions,

-Ed

Nov 15 '05 #2
Thank you for your reply. I still do not understand. .
Button09.Image = (Image) new Bitmap (this.GetType
(),"Resources.Images.Image1.ico");

All images are in the ../Resources/Images directory.
Take attention for the namespace. It must be the same.


Here's what I am hearing:

Step 1 - Manually create "/Resources/Images" subfolder underneath my C#
project directory and copy icon files into it

Step 2- Add all the files in the Images subfolder to my C# project. Set the
"Build Action" property for each image file to "Embedded Resource".

Step 3 - ???

It looks like you somehow created namespaces to match your
/Resources/Images" directory structure. How are the namespaces created for
your resources?

Thanks in advance,

-Ed
Nov 15 '05 #3
Also, how is the "Resource View" used in VStudio.NET?

In my C# project it is empty. It is not intuitive to me how to add
resources to it.

Thanks again,

-Ed
Nov 15 '05 #4
For future Google'ers here is my summary:

How to load icon from embedded resource into imageList
-------------------------------

1 - Add your *.ico file to your solution project. Pay attention to filename
case sensitivity. This is important.
2 - Set the "Build Action" property for this file to "Embedded Resource"
3 - Load the icons by using the Bitmap constructor that loads fro the
resources and cast to an Image.

// Load the images in an ImageList.
ImageList myImageList = new ImageList();
myImageList.Images.Add((Image)new Bitmap(GetType(), "Reader.ico"));
myImageList.Images.Add((Image)new Bitmap(GetType(), "Location.ico"));
myImageList.Images.Add((Image)new Bitmap(GetType(), "Logger.ico"));
In example above, if you did not pay attention to file name case
sensitivity, and you typed the following.

myImageList.Images.Add((Image)new Bitmap(GetType(), "READER.ICO"));

You would get an exception stating the resource could not be found in your
class.

-Ed
Nov 15 '05 #5

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

Similar topics

5
by: Greg | last post by:
Set Up Error - Failed to load resources from resource file Please check your set up. This plesently cordal and verbose error is greeting me in a very random and unpredictable way in a current VB...
3
by: Ramani | last post by:
Hi, We are running a ASP .NET application on Win2K server (.NET framework 1.1) I have recently started getting this error - Failed to load resources from resource file. I would like to...
0
by: Kevin P | last post by:
Hi News Group, In an application written in C# and VS.Net using Dotnet Framework 1.1.4322 on XP and Win 2000 machines, we randomly get the error "Failed to load resources from resource file....
0
by: Paul | last post by:
I have an existing application that has been installed and running for several months. I recently made a minor change to this application. When the application is installed on the user machine and...
3
by: Preference | last post by:
Hello, I am developing a .NET application in managed C++. Until now we have executed without problems in a lot of different computers. But a few days ago we detect a problem in some laptops. In...
2
by: Paul Cheetham | last post by:
Hi, I am trying to load a custom cursor from my programs resources. I have successfully included the cursor resource, and I have confirmed that the name I am using is correct. Below is the...
4
by: bclegg | last post by:
Hi, I am getting the above error when start my application which I deployed successfully. The msi was produced using a .net launch project. I can't see how to dig deeper to find out what is...
1
by: =?Utf-8?B?QWRhbQ==?= | last post by:
I'm having a problem loading an Icon into an ImageList. When I load the icon directly it works fine, like this: Icon sourceIcon = << Get an icon from somewhere... >>;...
0
by: Pitaridis Aristotelis | last post by:
I know how to extract an embeded resource from a file but does anyone how to import an embeded resource to a file?
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.