Export (0) Print
Expand All

How to: Add or Remove Resources 

You can use the Resource Designer to add or edit resources for your project. Resource types supported by the Resource Designer include strings, images, icons, audio, and files. For information on how the Resource Designer maintains resources and designer information, see Resources Page, Project Designer.

The Resource Designer is language-neutral and supports projects in all of the Visual Studio languages. For Visual C# and Visual J#, 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# and Visual J#, 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 through the My.Resources object, see Accessing Application Resources.

NoteNote

The procedures for adding and removing string resources differ from the other resource types. For more information, see How to: Add or Remove String Resources.

NoteNote

When you add a new image to a project, the Resource Editor does not add a reference to System.Drawing, which is necessary for compilation.

In addition to the tasks listed below, you can add resources using drag and drop to the Resource Designer. When dropped, the resource is added to the appropriate resource category based on its file extension.

If you add a resource manually to the project (for example, by adding a .resx file using Solution Explorer), the resources in the new file will be separate from the resources you create using the Resource page of the Project Designer. If you double-click the new .resx file, a separate Resource Designer window will open, displaying the file's contents in a settings grid. Note that when you add the new .resx file, you will be prompted with a message asking, "Do you want to enable strongly-typed resource generation for this file?" Clicking Yes will give the new resource strongly-typed resource support, a compile-time feature that encapsulates access to resources by creating classes that contain a set of static, read-only (get) properties. This provides the preferred way to consume resources, rather than using the GetString and GetObject methods of the ResourceManager class. For more information, see StronglyTypedResourceBuilder.

To add an existing resource

  1. With a project selected in Solution Explorer, on the Project menu click Properties.

  2. Select the Resources tab.

  3. On the Resource Designer toolbar, point to Add Resource, click the arrow, then click Add Existing File.

  4. In the Add existing file to resources dialog box, browse to the file containing the resource that you wish to add (.bmp, .ico, .wav, etc,), and then click Open.

    The file will be added to the Resources directory, and the Resource Designer will open the Category pane for the resource type that you added.

  5. For file resources, you can optionally set the Encoding and FileType properties for the file in the Properties window.

To add a new resource

  1. With a project selected in Solution Explorer, on the Project menu click Properties.

  2. Select the Resources tab.

  3. On the Resource Designer toolbar, point to Add Resource, click the arrrow, and click the type of resource you want to create.

  4. In the Add new resource dialog box, enter a name for the new resource, and then click Add.

    The file will be added to the Resources directory, and a resource editor will open for the resource type that you added.

  5. For file resources, you can optionally set the Encoding and FileType properties for the file in the Properties window.

To remove a resource

  1. With a project selected in Solution Explorer, on the Project menu click Properties.

  2. Select the Resources tab.

  3. Select a resource type from the Categories dropdown list.

  4. Select the resource that you wish to remove.

  5. On the Resource Designer toolbar, click Remove Resource.

    The resource will be removed from the Resource Designer, but it will not be removed from the Resources directory.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft