Where to add string resources in a WinForms project.

G

Guest

I have added some strings as resources to the resx file of my main Form.cs
file (these are strings that are not a part of the Forms design) . I have
added the strings manually in the Data view of the resx file editor i Visual
Studio. The problem is that when I modify the Form in the designer view all
the strings that I typed manually are lost -they are deleted probably because
the resx file is completely or partly auto generated from the cs file.

This probably is the wrong approach. Any ideas on how to add strings as
resources so that they can be translated into satelite assemblies.
 
G

Guest

hi
you should not it do on the forms resource
instead create another file using resource writer
and call the file using resource manager class
here is an eg

using System;
using System.Resources;


public class WriteResources {
public static void Main(string[] args) {

// Creates a resource writer.
IResourceWriter writer = new ResourceWriter("myResources.resources");

// Adds resources to the resource writer.
writer.AddResource("String 1", "First String");

writer.AddResource("String 2", "Second String");

writer.AddResource("String 3", "Third String");

// Writes the resources to the file or stream, and closes it.
writer.Close();
}
}
this will create a file myResources.resources and store the data in it
now calling it in youe project

Add the file myResources.resources to ur project

now u can use ResourceManager calss to access the resource
ResourceManager resMan=new
ResourceManager(myAssemblyname.myResources,Assembly.GetExecutingAssembly();

replace the "myAssemblyname" with the assembly of yours
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top