Embedded Resources

  • Thread starter Thread starter Brian Reed
  • Start date Start date
B

Brian Reed

How can I embedd an icon in my PocketPC application and then load it. I
have added an ico file to the project and set it to build as an embedded
resource, but in my code when I try to load the icon, the only available
options are from a stream. Are there any steps I am missing? What coding
mechanism do I use to access bitmaps and resources in the embedded
executable?

Thanks,
 
Use Assembly.GetExecutingAssembly().GetManifestResourceStream() method to
obtain a stream object for an embedded resource. Icon and Bitmap contructors
accept Stream as a source.
If you are having a problem with figuring out the proper resource name, use
Assembly.GetExecutingAssembly().GetManifestResourceNames to see what names
are there.
 
Yes. It might be embedding the icon in my executable, but I still am not
sure what method to use to load the icon from it? Only two of the icon
constructors are valid for the compact framework and they all require stream
inputs.
 
I tried using your suggested code and I could not get it to compile. It
complains about 'Assembly' and gives the following error:

G:\MineCollector\CMainForm.cs(658): The type or namespace name
'GetExecutingAssembly' does not exist in the class or namespace 'Assembly'
(are you missing an assembly reference?)


I tried looking at the project settings to see what the value of the
'Assembly Name' is and when I use that in place of 'Assembly' I get the same
error.

I have tried compiling the ResEditor.exe app in the SDK and used it to
create a resX file. I added that to the project as an embedded resource and
it fails to build stating that:

G:\MineCollector\Icons.resX Resource transformation for file 'Icons.resX'
failed. Type System.Drawing.Icon cannot be compiled into the .resources
file. This type is not supported for .NET Compact Frameworks.

This is the most frustrating thing I have done with .NET. I can't believe
it is so hard to get an embedded resource into my PocketPC application!!
 
You need to reference System.Reflection in your code via "using" or
explicitly.

System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
)
 
I am sorry I didn't take the time to research that more. I should have
realized that I just needed to find the proper reference. I got it working.
Thanks so much!!
 
Back
Top