resx只是一个form的结构定义罢了,当然,你可以在定义的时候给某个控件加上名称属性之类的。但是这些东西在compile之后就无法修改了,而resouce里面的信息就不同了,因此我们用.resource文件来实现本地化。Run resource generator utility on this resource file by using the Visual Studio .NET command prompt. The command for generating a .resources file is:Resgen MyResource.en-GB.resxThis will create a binary version of the above resource file named, MyResource.en-GB.resources.
using System.Resources;
using System.Drawing;namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
ResourceWriter rw = new ResourceWriter(@"D:\ConsoleApplication1\obj\Debug\wwww.resources");
using (Image image = Image.FromFile(@"D:\ConsoleApplication1\obj\Debug\logo.gif"))
{/*
* 在 using 语句中创建一个实例,确保退出 using 语句时在对象上调用 Dispose。
* 当到达 using 语句的末尾,
* 或者如果在语句结束之前引发异常并且控制离开语句块,都可以退出 using 语句。
*
*/ rw.AddResource("WroxLogo", image);
rw.AddResource("Title", "Professional C#");
rw.AddResource("Chapter", "Assemblies");
rw.AddResource("Author", "Christian Nagel");
rw.AddResource("Publisher", "Wrox Press");
rw.Close();
}
}
}
}例外一个工程中下面代码装载上面创建的资源Assembly assembly = Assembly.GetExecutingAssembly(); rm = new System.Resources.ResourceManager("WindowsApplication1.wwww",assembly); logo.Image = (Image)rm.GetObject("WroxLogo");
textBoxTitle.Text = rm.GetString("Title");
textBoxChapter.Text = rm.GetString("Chapter");
textBoxAuthor.Text = rm.GetString("Author");
textBoxPublisher.Text = rm.GetString("Publisher");
Generated Access to .NET Resource Strings
http://www.codeproject.com/csharp/genresourcekeys.asp?target=%2Eresource资源文件常用来解决本地化问题
.NET - Localization using Resource file
http://www.codeproject.com/dotnet/Localization.asp?target=%2Eresource