Dela via


How to: Add or Remove String Resources

You can use the Resource Designer to add or edit string resources for your Visual Basic or C# project. The procedures for adding and removing string resources differ from those of other resource types. For information about how to manage non-string resource types, see How to: Add or Remove Resources.

We do not recommend that you use string resources for large strings, because they are hard to edit, and there is a limit of 32767 characters. Instead, add a text file by using Add New Text File from the Add Resource list in the Resource Designer. The new text file will be added to the Resources directory. It can contain as much text as you want, and you can set the encoding if you need to. However, when you compile the program, it will appear as if it had been entered in the string table.

If you add a string 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 that you create by 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. 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 an alternative way to consume resources, instead of using the GetString and GetObject methods of the ResourceManager class. For more information, see StronglyTypedResourceBuilder.

You can also add string resources by using drag-and-drop editing with the Resource Designer. When you drag and drop strings, the Name, Value, and Comment fields must be separated by tab stops or the whole string will be added to the Name column.

For information about how the Resource Designer generates strongly-typed resources, see Managing Application Resources.

To add a string resource

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

  2. Click the Resources tab. On the Resource Designer toolbar, point to the resource view drop-down, click the arrow, and make sure that it is set to Strings (which is the default). A settings grid will appear, displaying the strings maintained by that instance of the Resource Designer.

  3. Click the Name column of the last row in the grid, which is marked with an asterisk (*).

  4. In the Name column, enter a name for the string.

  5. In the Value column, enter the string that you want to use as a resource.

    Note

    To include line breaks (CLRF characters) in your string, type Shift + Enter. You will have to resize the row to be able to see all the lines in your string. Position the pointer on the bottom border of the row in the leftmost column of the grid, and then click and drag the border down to resize.

  6. Optionally, enter a comment in the Comment column.

    Note

    Comments are not compiled into the application; they are available only at design time.

To remove a string resource

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

  2. Click the Resources tab.

  3. On the Resource Designer toolbar, point to the resource view drop-down, click the arrow, and make sure that it is set to Strings (which is the default).

  4. Select the row that contains the string you want to remove by clicking in the gray row header.

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

See Also

Tasks

How to: Edit String Resources

How to: Add or Remove Resources

How to: Edit Resources

Reference

My.Resources Object

Concepts

Accessing Application Resources (Visual Basic)

Other Resources

Managing Application Resources

Resources Page, Project Designer