Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

Resources in .NET Solutions

On the .NET platform we can add images, icons, strings, and text files as resources to our solutions. To add resources we select the Resources tab from the .NET solution Properties window and click the Add Resource button on its toolbar. All resources associated with a solution become part of the EXE or DLL file upon compilation of the solution.

To work with resources in code, we use My.Resources together with the name of the resource file. Listing 24-29 shows how we use an icon resource in code.

Listing 24-29. Associate an Icon Resource File to a Windows Form

Me.Icon = My.Resources.PetrasIcon

In this example, the Me keyword refers to a Windows Form, and PetrasIcon refers to an icon resource file. The My keyword refers to the My namespace that the .NET Framework makes available for all VB.NET solutions. This namespace exposes seven objects that allow us to work with various resources and features. Table 24-3 lists the My namespace objects along with the purpose of each.

Table 24-3. Objects in the My Namespace




Provides information about the application such as path, assembly information, and environment variables.


Provides features for manipulating computer components such as audio, the clock, the keyboard, the file system, and so on.


Provides access to all Windows Forms in the solution.


Provides access to resources used by the solution.


Allows reading and storing application configuration settings.


Provides access to information about the current user, including whether or not the user belongs to a special user group.


Provides features for creating and accessing a single instance of each XML Web service referenced by the solution.

  • + Share This
  • 🔖 Save To Your Account