40.4. Accessing Specifics

Numerous shortcuts have been built into the .NET Framework to support the most common tasks related to accessing resources. These shortcuts include single-line image loading, cross-assembly referencing, and the use of the ComponentResourceManager class.

40.4.1. Bitmap and Icon Loading

Images and icons are two of the most common data types held in resource files. Therefore, both the Bitmap and Icon classes in the framework support a constructor that can create an instance directly from a resource without the need for a resource manager. For example, if you have an image, MyImage.bmp, that you included in your project by setting the build action to Embedded Resource, you can access the image directly using the following code:

Dim img As New Bitmap(GetType(ThisClass), "MyImage.bmp")

Here the class, ThisClass, can be any class in the root namespace of the project that contains the embedded resource.

40.4.2. Cross-Assembly Referencing

One of the features added to the resource editor in Visual Studio 2008 is the ability to control the accessibility level for resource files. In the past, if you wanted to make resources defined in one assembly accessible from another you had to do a lot of hard work and write custom code. Now, with the Access Modifier option in the resource editor, as shown in Figure 40-7, you can choose between keeping a resource internal to the assembly it is defined in (Friend) or making it publicly accessible (Public).

Figure 40.7. Figure ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.