M
Michael Casey
There appears to be a few options for defining and accessing resources
within managed applications. Most of the documentation discusses
localization of global applications, but I'm just looking for an explanation
on how to embed a bitmap and load it at runtime. To be clear, I don't want
to use the designer to associate the image with a specific control (e.g.
picture box) at design time, I want to embed the image in the assembly, so
that it can be associated with a control (e.g. picture box) at run-time.
The motivation for this is that the a unique image will be loaded by one of
several assemblies that in turn will invoke a common Windows Form (compiled
within a separate library), and display the unique image in a picture box of
that common windows form.
Using the resource manager object I can reference images contained within an
independent resource file (i.e. using CreateFileBasedResourceManager), but
this file needs to be edited independently of the Visual Studio Project and
deployed in the appropriate directory. In other words, the resource file is
not part of the assembly, so the file is simply loaded at runtime. In
addition, there is the problem of source controlling these resource files.
Since independently managed resource files are expected to reside within the
run-time directory, it must be available within the <project
directory>/bin/debug subdirectory for Visual Studio Debugging. The only way
to make this readily available is to source control this file in this
subdirectory; however, this doesn't seem right - I would rather have all
source code maintained within the root directory of the project.
Alternatively, I can use a resource file editor to edit the contents of the
resource file associated with any windows form. This way, I avoid the
problem of having to maintain separate resource files, and making sure the
files are deployed into the proper location (since it's already included in
the assembly), but I still can't see what resources are available from
within Visual Studio. Furthermore, the image is then being maintained with
a resource file associated with one form, while the image is to be extracted
and displayed on another form. This is certainly not intuitive, and
difficult to maintain.
Within Visual Studio, I can add resource files (i.e. bmp files) to the
project, but I can't seem to figure out how to access the content's of this
file. Are these images incldued in the assembly, or is this just a way of
keeping images source controlled with a project? Reading the documentation,
I understand that images added to "resource" files can not be edited
directly in visual studio. I'm not necessarily concerned about editing the
images within Visual Studio, I simply want to be able to add, and inspect
images at design time, while not actually associating the image with a
control until run time (and not having to worry about copying additional
files at deployment). What I can't figure out is the code needed to access
thes images at run time.
To summarize, what I'm looking for (if possible) is the following:
1) Add either an image file (bmp) or resource file (resx) to a project.
2) If using a resx file, and a bitmap file to this resource file using a
resource file editor
3) After compiling the program, the assumption is that the bitmap image is
embeded into the assembly
4) At run-time reference the image to be displayed within a form of another
assembly, by passing the image as an object.
Can anyone suggest the best approach for this (with details about how the
image is referenced)?
within managed applications. Most of the documentation discusses
localization of global applications, but I'm just looking for an explanation
on how to embed a bitmap and load it at runtime. To be clear, I don't want
to use the designer to associate the image with a specific control (e.g.
picture box) at design time, I want to embed the image in the assembly, so
that it can be associated with a control (e.g. picture box) at run-time.
The motivation for this is that the a unique image will be loaded by one of
several assemblies that in turn will invoke a common Windows Form (compiled
within a separate library), and display the unique image in a picture box of
that common windows form.
Using the resource manager object I can reference images contained within an
independent resource file (i.e. using CreateFileBasedResourceManager), but
this file needs to be edited independently of the Visual Studio Project and
deployed in the appropriate directory. In other words, the resource file is
not part of the assembly, so the file is simply loaded at runtime. In
addition, there is the problem of source controlling these resource files.
Since independently managed resource files are expected to reside within the
run-time directory, it must be available within the <project
directory>/bin/debug subdirectory for Visual Studio Debugging. The only way
to make this readily available is to source control this file in this
subdirectory; however, this doesn't seem right - I would rather have all
source code maintained within the root directory of the project.
Alternatively, I can use a resource file editor to edit the contents of the
resource file associated with any windows form. This way, I avoid the
problem of having to maintain separate resource files, and making sure the
files are deployed into the proper location (since it's already included in
the assembly), but I still can't see what resources are available from
within Visual Studio. Furthermore, the image is then being maintained with
a resource file associated with one form, while the image is to be extracted
and displayed on another form. This is certainly not intuitive, and
difficult to maintain.
Within Visual Studio, I can add resource files (i.e. bmp files) to the
project, but I can't seem to figure out how to access the content's of this
file. Are these images incldued in the assembly, or is this just a way of
keeping images source controlled with a project? Reading the documentation,
I understand that images added to "resource" files can not be edited
directly in visual studio. I'm not necessarily concerned about editing the
images within Visual Studio, I simply want to be able to add, and inspect
images at design time, while not actually associating the image with a
control until run time (and not having to worry about copying additional
files at deployment). What I can't figure out is the code needed to access
thes images at run time.
To summarize, what I'm looking for (if possible) is the following:
1) Add either an image file (bmp) or resource file (resx) to a project.
2) If using a resx file, and a bitmap file to this resource file using a
resource file editor
3) After compiling the program, the assumption is that the bitmap image is
embeded into the assembly
4) At run-time reference the image to be displayed within a form of another
assembly, by passing the image as an object.
Can anyone suggest the best approach for this (with details about how the
image is referenced)?