Access resource files for .NET forms
- Last Updated: November 1, 2022
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
.NET supports a file type for storing resources, such as graphics and images, that a form uses. These resource files are XML files with the .resx filename extension. In .NET, you typically create one resource file for a given form class and give it a filename that is the same as the name of the given form class, and store it with the source file for the class. In ABL, you might give it the same filename as an ABL-derived .NET form class for which the resources are designed, and store it with the ABL class file. The Visual Designer in Progress Developer Studio for OpenEdge automatically creates this file for any ABL-derived form to which you add resources. For more information on creating such resource files yourself, see the .NET documentation.
In order to retrieve resources from a given
resource file, OpenEdge provides the .NET Progress.Util.ResourceHelper class.
This class provides a single Load( ) method
that allows you to retrieve the complete set of resources from a
resource file. To call the method, you specify two INPUT parameters
as CHARACTER expressions:
- A pathname that includes the filename (and extension) of the resource file. This can be an absolute or relative path, depending on the second parameter.
- Either a non-empty comma-separated list of pathnames (typically PROPATH) or an empty string (
""). If it is non-empty, the first parameter must specify a file relative to a path on the list. Otherwise, the first parameter must specify a file either as an absolute pathname or as a pathname relative to the current working directory.
The Load( ) method returns an object
reference to a System.Resources.ResXResourceSet. This is a
.NET object that stores the resources of a resource file as objects that you can access by
name. This class provides a GetObject( ) method that you
can use to return a specific resource object given its name.
The
following code fragment loads a resource file, form1.resx,
from PROPATH into a resources object
(rResources). It then returns an image object named "open.Image" from rResources using
the GetObject( ) method:
|