Dela via


Resources Page, Project Designer

The Resource Designer is a user interface tool that enables you to manage resources (such as strings, images, icons, audio, and other files) for your project.

The Resources page of the Project Designer hosts an instance of the Resource Designer that stores and maintains resources in a single location (Resources.resx).

The Resource Designer is language-neutral and supports projects in all Visual Studio languages. Items that you add to the project by using the Resource Designer are placed in the Resources directory for your project. The designer information is stored in a file named Resources.resx, and code for the resource is stored in Resources.Designer.cs, Resources.Designer.vb, or Resources.Designer.jsl.

You can also use the Resource Designer to edit stand-alone .resx files. For example, if you add a resource file by using Solution Explorer, its settings are kept in a separate .resx file and do not appear in the Project Designer. Double-clicking a resource's .resx file opens a separate Resource Designer for that resource.

You can edit file-based resources by double-clicking the resource in the Resource Designer. The Resource Designer opens the item in the default editor for that file type. If no editor is registered for that file type, the file is opened in the Windows default application for that type. To change the file type association, see How to: Associate an Editor with a Resource Type.

For Visual C#, the Resource Designer generates strongly-typed resources in the project's default namespace (specifically, ProjectName.Properties in Resources.Designer.cs). For information about accessing resources in Visual C#, see Adding and Editing Resources (Visual C#).

For Visual Basic, the Resource Designer generates strongly-typed resources in the My.Resources namespace (in Resources.Designer.vb). For information about accessing resources in Visual Basic by using the My.Resources object, see Accessing Application Resources.

Strongly-typed resources encapsulate access to resources by creating classes that contain a set of static, read-only (Get) properties at compile time. You can consume resources by using the Get properties rather than using the GetString and GetObject methods of the ResourceManager class. Strongly-typed resources also make it easier to develop localizable applications. For information about strongly-typed resources, see StronglyTypedResourceBuilder.

Resources also have a Persistence property that specifies whether they are linked or embedded. Linked resources are stored as files within the project; the .resx file stores a relative path to the file, and during compilation, the resource data is placed into the manifest for the application. With embedded resources, the resource data is stored directly in the .resx file.

By default, all new resources are linked resources, as opposed to embedded. If you try to edit an embedded resource, you will receive a message prompting you to convert the item to a linked resource in order to edit it; conversion is recommended but optional. For more information, see Linked and Embedded Resources.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To access the Resources page, select a project node in Solution Explorer, and then, on the Project menu, click Properties. When the Project Designer appears, click the Resources tab.

Resource View Selector

To view a project's resources by type, at the top-left corner of the Resources page, click the arrow and select a resource type from the drop-down list. The choices are Strings, Images, Icons, Audio, Files, and Other. Strings is the default view. The following list describes the various views.

  • Strings
    Displays strings in a grid that has columns for the Name, Value, and Comment of the string resource. You can access the resources as String by using My.Resources at run time. For a description of the columns in this grid, see the Settings Grid section later in this topic.

  • Images
    Displays all image files, including .bmp, .jpg, and .gif formats. These files are exposed at run time as Bitmap. This category also includes Windows metafiles, exposed as Metafile.

  • Icons
    Displays icon (.ico) files, which are exposed as Icon.

  • Audio
    Displays sound files, including .wav, .wma, and .mp3 files. These files are exposed as byte arrays. Double-clicking an audio item opens it and plays it in Windows Media Player.

  • Files
    Displays any files that do not fit into the above categories. Items in this view can be text files exposed as String, or binary files exposed as byte arrays.

  • Other
    Displays a settings grid for adding other types that support string serialization (for example, Font, Enum, Color, and Point). The grid contains the following columns: Name, Type, Value, and Comment. For a description of the columns in this grid, see the Settings Grid section later in this topic.

Add Resource, Remove Resource, and Access Modifier

These controls enable you to add and delete resources. They also enable you to change the access level of generated My.Resources classes.

  • Add Resource
    Select an item from the Add Resource drop-down list at the top of the page to add a resource. The options are Add Existing File, Add New String, New Image (PNG, BMP, GIF, JPEG, or TIFF format), Add New Icon, and Add New Text File.

  • Remove Resource
    Select an existing resource in the settings grid (described below) and click Remove Resources to delete it.

  • Access modifier
    This option is available in Resource Designers for resource files that you add to a project and in the default Resource Designer (Resources.resx).

    This option specifies the access level of the My.Resources helper classes that Visual Studio generates in Resources.Designer.cs or Resources.Designer.vb. My.Resources classes provide runtime access to resources.

    For Visual C# projects, the access modifier can be Internal, Public, or No code generation.

    For Visual Basic projects, the access modifier can be Friend, Public, or No code generation.

    By default, the setting is Internal (in C#) or Friend (in Visual Basic). When Visual Studio generates helper classes as Internal or Friend, executable (.exe) applications cannot access the resources and settings that you have added to class libraries (.dll files). If you need to share resources and settings from a DLL, set the access modifier to Public.

    For localized resource files (for example, ProjectName.de-DE.resx), you should set the access modifier to No code generation so that your application automatically accesses the appropriate localized resource file at run time. For more information about localized resources, see How to: Create a Localized Version of a Resource File. The access modifier No code generation is not available for the default Resource Designer.

Settings Grid

The settings grid is used to configure settings for string resources. This grid appears only in the Strings view and in the Other view. The grid includes the following columns.

  • Name
    Type the name of the resource in this field.

  • Type
    Specify a type that supports string serialization. (This column appears only in the Other view.)

  • Value
    Specify the value associated with the resource setting. For example, if the resource is a string, you would type its text value here.

  • Comment
    Optionally, type a comment that describes the string resource. You can view this only at design time.

See Also

Tasks

How to: Add or Remove Resources

How to: Add or Remove String Resources

How to: Edit Resources

How to: Edit String Resources

How to: Associate an Editor with a Resource Type

How to: Create Embedded Resources

How to: Import or Export Resources

Concepts

Linked and Embedded Resources

Accessing Application Resources

Other Resources

Managing Application Resources