Using images on windows forms, stored in a dotnet assembly (dll).

  • Thread starter Thread starter Emmanuel
  • Start date Start date
E

Emmanuel

Hi,

I am creating a multi assembly windows application.

I want to store all the images or/and icons of my application to a single
dll (as resources ?) and use them from there, when needed, on other
assemblies containing windows forms.

I want to be able to use them from code (using enumerations for example) and
from the designer when designing windows forms (if possible).

Does anyone know, how can I accomplish this technic ?

Thank you

Emmanuel
 
Hi Emmanuel,

Thanks for your posting!!

In .Net, the assembly that only contains resource is called Satellite
Assembly. So we may store the resource in Satellite Assemblies, then
manipulate the resource from them.

For how to create Satellite Assemblies, please refer to:
"Creating Satellite Assemblies"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcreatingsatelliteassemblies.asp

For how to retrieve resource from Satellite Assemblies, please refer to:
"Retrieving Resources in Satellite Assemblies"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconlocalizingresources.asp
"How to read satellite assemblies resources in ASP.NET"
http://www.codeproject.com/aspnet/SatResourcesDemo.asp

Here is a C# sample project for how to operating Satellite Assemblies:
"LocalizedHelloWorld Sample: Demonstrates Satellite Assemblies for Console
Applications"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cssample/ht
ml/vcsamLocalizedHelloWorld.asp

Hope this helps.
==============================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Jeffrey,

thank you for your feedback.
I have read most of the articles but there are some things that are not yet
clear to
me:

In order to store the images/icons to resource files and from them create
the satellite assemblies, do I have to write a separate program that does
the job ?

Is there a way to do this using the Visual Studio interface ?


CREATING THE RESOURCES:

Can I Create the .resources, or whatever file is needed, using the VS
interface ?
Can I then place this resource file inside a new project which I will
include in my solution ?



USING THE RESOURCES IN VISUAL STUDIO FORM DESIGNER:

I thing that I understand how can I use the resources inside a satellite
assembly using code.
I can just repeat the code that the forms designer generates when creating a
form that contains resources.

But how can I use the satellite assembly and its resources inside the
designer ???

If I want to use an Icon or bitmap that it is stored in a satelite assembly
how can I refer to it when
I am in the Forms Designer. For example, let's say that I want to place a
bitmap/icon from the
satellite assembly to a windows form button. How can I do that, using the
designer ?



For the moment I am not interested at all for form localization issues.

Thanks again

Emmanuel
 
Hi Emmanuel,

Welcome to .net community. As for the .net resource files and satellite
assemblies, they are pure resources containers which only contains resource
objects( string , image or other serializable objects). Also, resource
file and satellite assembly are all binary files which are not human
readable. So we can manually embed .resource file into VS.NET project, but
it display it as binary file (not readable or editable format).

In fact, in VS.NET we use .resx( assembly resource file) to manipulate
resources. And when we build our project, the VS.NET will compile the .resx
file into .resource file and embeded the generated resource file into main
assembly(or satellite assembly) according to its cultureinfo.

So the first question you mentioned:
CREATING THE RESOURCES:

I think we can just create ".resx" file (add new item----> assembly
resource file) and add items into it. But the VS.NET IDE dosn't provide
full support for editing .resx file. If we want to add some binary data
such as image or our custom objects, it is recommended that we create a
separate application to generate resource (.resx). And the "ResEditor" is a
good tool (shipped with VS.NET as buildin tool in whidbey) for editing
existed resource or resx file).

USING THE RESOURCES IN VISUAL STUDIO FORM DESIGNER:

As for using resource in VS.NET design-time, I'm afraid there hasn't been
any means currently. As we could see, when we create different
resource(.resx) file for a locallized form , the VS.NET's design-time work
is just generate the code in the InitializeComponents method , and those
auto generated code also use the ResourceManager to retrieve the objects
from the assembly's embeded resources. So there is no means to directly use
items in resource files at design-time( at least no buildin api now).

Thanks & Regards,

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Steven,

thank you very much for your answer.

But to clarify the things a little bit I would summarize your answer to the
following:

If someone wants to develop a "Word-Ready Application" as mentioned at the
..NET's Framework help file, and wants to put together the images and other
resources used in the application in an assembly file (dll), he has only one
way of doing it:

THE GOOD
===========
Creating the resources:
He should create another windows application, that gathers all resources
from the development directories and stuffs them inside a .resource file.
The resource file is then embeded inside the assembly during compilation
process. The class involved is the System.Resources.ResourceWriter class and
the related.

Using the resources:
Resources that reside in a separate satellite assembly can be used ONLY BY
CODE. using the System.Resources.ResourceReader class and the related.

THE BAD
=======
So Visual Studio integrated environment:

1. Cannot in any way create resource files (with images of course) nor you
can edit resource files with the tools provided by Visual Studio .NET 2003.
(A new tool called "ResEditor" will be available when the new version of
Visual Studio becomes available...)

2. The resource files in satellite assemblies cannot be used by the Form
Designer. So you cannot design forms using resources that reside in a
different satellite assembly.

Thanks again
Emmanuel
 
Thanks for your followup Emmanuel,

Yes, the currently resource manipulation support in VS.NET( until 2003) are
limited. And we can manually create and edit resx file(not .resource) file
and even the resx file's manipluation is limited( there hasn't a good edior
for resource in the current IDE). And form designer's support for resource
manipulation( for resx file) are only available when we dealing with
localizable form.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top