原来在vb里面是去数据库读指,在赋值给label啊,Button的Text什么的,但现在.net里面不要这样做了。看了些关于全球化的在msdn和其他地方,感觉还是没弄明白。
问题:
在项目里直接添加Resource1.resx,然后如何去读取它,用ResourceManage去读取这里有问题,
我不清楚如何去使用这个Resource1.resx,如果可以,那么根据用户的选择去读取不同的*.resx文件就好了。
6 个解决方案
#1
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbtsksettingcultureuicultureforwebformsglobalization.htm
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vboriinternationalization.htm
希望能对你有帮助
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vboriinternationalization.htm
希望能对你有帮助
#2
这个msdn看过了,csdn上的帖子也搜过。问题的关键在上面说的
#3
那个大哥说说?
#4
namespace SkinTest
{
public class LoginLanguage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
ListItem li=new ListItem("Enlish","en-US");
this.DropDownList1 .Items .Add(li);
li=new ListItem("中国","zh-CN");
this.DropDownList1 .Items .Add(li);
li=new ListItem("French","fr-FR");
this.DropDownList1 .Items .Add(li);
}
// Request.UserLanguages[0].ToString();
ResourceManager LocRM =new ResourceManager( "SkinTest.Resource",typeof(LoginLanguage).Assembly);
注意这里是namespace.加资源文件名(Resource.en-US.resx中的Resource
string lang=DropDownList1.SelectedValue ;
if (lang ==null) lang="en-US";
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
// Sets the UI culture to French (France)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
this.Label1 .Text = LocRM.GetString("user");
this.Label2 .Text = LocRM.GetString("password");
this.Button1 .Text = LocRM.GetString("login");
}
html
<HTML>
<HEAD>
<title>LoginLanguage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 352px; POSITION: absolute; TOP: 160px" runat="server"
Width="96px">用户</asp:Label>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 552px; POSITION: absolute; TOP: 80px"
runat="server" AutoPostBack="True"></asp:DropDownList>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 480px; POSITION: absolute; TOP: 160px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 104; LEFT: 480px; POSITION: absolute; TOP: 208px"
runat="server"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 360px; POSITION: absolute; TOP: 200px" runat="server"
Width="80px">密码</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 106; LEFT: 480px; POSITION: absolute; TOP: 280px" runat="server"
Text="登录"></asp:Button>
</form>
</body>
</HTML>
在project中加三个资源文件
Resource.en-US.resx
Resource.fr-FR.resx
Resource.zh-CN.resx
内宾为
<data name="login">
<value>login</value>
</data>
<data name="password">
<value>login</value>
</data>
<data name="user">
<value>login</value>
</data>
<data name="login">
<value>登录</value>
</data>
<data name="password">
<value>密码</value>
</data>
<data name="user">
<value>用户</value>
</data>
<data name="login">
<value>xxxx</value>
</data>
<data name="password">
<value>yyyyyyy</value>
</data>
<data name="user">
<value>zzzzzz</value>
</data>
{
public class LoginLanguage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
ListItem li=new ListItem("Enlish","en-US");
this.DropDownList1 .Items .Add(li);
li=new ListItem("中国","zh-CN");
this.DropDownList1 .Items .Add(li);
li=new ListItem("French","fr-FR");
this.DropDownList1 .Items .Add(li);
}
// Request.UserLanguages[0].ToString();
ResourceManager LocRM =new ResourceManager( "SkinTest.Resource",typeof(LoginLanguage).Assembly);
注意这里是namespace.加资源文件名(Resource.en-US.resx中的Resource
string lang=DropDownList1.SelectedValue ;
if (lang ==null) lang="en-US";
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
// Sets the UI culture to French (France)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
this.Label1 .Text = LocRM.GetString("user");
this.Label2 .Text = LocRM.GetString("password");
this.Button1 .Text = LocRM.GetString("login");
}
html
<HTML>
<HEAD>
<title>LoginLanguage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 352px; POSITION: absolute; TOP: 160px" runat="server"
Width="96px">用户</asp:Label>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 552px; POSITION: absolute; TOP: 80px"
runat="server" AutoPostBack="True"></asp:DropDownList>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 480px; POSITION: absolute; TOP: 160px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 104; LEFT: 480px; POSITION: absolute; TOP: 208px"
runat="server"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 360px; POSITION: absolute; TOP: 200px" runat="server"
Width="80px">密码</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 106; LEFT: 480px; POSITION: absolute; TOP: 280px" runat="server"
Text="登录"></asp:Button>
</form>
</body>
</HTML>
在project中加三个资源文件
Resource.en-US.resx
Resource.fr-FR.resx
Resource.zh-CN.resx
内宾为
<data name="login">
<value>login</value>
</data>
<data name="password">
<value>login</value>
</data>
<data name="user">
<value>login</value>
</data>
<data name="login">
<value>登录</value>
</data>
<data name="password">
<value>密码</value>
</data>
<data name="user">
<value>用户</value>
</data>
<data name="login">
<value>xxxx</value>
</data>
<data name="password">
<value>yyyyyyy</value>
</data>
<data name="user">
<value>zzzzzz</value>
</data>
#5
这就是资源文件,网上这些资料很多
#6
没仔细研究过资源文件,不会
#1
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbtsksettingcultureuicultureforwebformsglobalization.htm
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vboriinternationalization.htm
希望能对你有帮助
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vboriinternationalization.htm
希望能对你有帮助
#2
这个msdn看过了,csdn上的帖子也搜过。问题的关键在上面说的
#3
那个大哥说说?
#4
namespace SkinTest
{
public class LoginLanguage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
ListItem li=new ListItem("Enlish","en-US");
this.DropDownList1 .Items .Add(li);
li=new ListItem("中国","zh-CN");
this.DropDownList1 .Items .Add(li);
li=new ListItem("French","fr-FR");
this.DropDownList1 .Items .Add(li);
}
// Request.UserLanguages[0].ToString();
ResourceManager LocRM =new ResourceManager( "SkinTest.Resource",typeof(LoginLanguage).Assembly);
注意这里是namespace.加资源文件名(Resource.en-US.resx中的Resource
string lang=DropDownList1.SelectedValue ;
if (lang ==null) lang="en-US";
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
// Sets the UI culture to French (France)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
this.Label1 .Text = LocRM.GetString("user");
this.Label2 .Text = LocRM.GetString("password");
this.Button1 .Text = LocRM.GetString("login");
}
html
<HTML>
<HEAD>
<title>LoginLanguage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 352px; POSITION: absolute; TOP: 160px" runat="server"
Width="96px">用户</asp:Label>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 552px; POSITION: absolute; TOP: 80px"
runat="server" AutoPostBack="True"></asp:DropDownList>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 480px; POSITION: absolute; TOP: 160px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 104; LEFT: 480px; POSITION: absolute; TOP: 208px"
runat="server"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 360px; POSITION: absolute; TOP: 200px" runat="server"
Width="80px">密码</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 106; LEFT: 480px; POSITION: absolute; TOP: 280px" runat="server"
Text="登录"></asp:Button>
</form>
</body>
</HTML>
在project中加三个资源文件
Resource.en-US.resx
Resource.fr-FR.resx
Resource.zh-CN.resx
内宾为
<data name="login">
<value>login</value>
</data>
<data name="password">
<value>login</value>
</data>
<data name="user">
<value>login</value>
</data>
<data name="login">
<value>登录</value>
</data>
<data name="password">
<value>密码</value>
</data>
<data name="user">
<value>用户</value>
</data>
<data name="login">
<value>xxxx</value>
</data>
<data name="password">
<value>yyyyyyy</value>
</data>
<data name="user">
<value>zzzzzz</value>
</data>
{
public class LoginLanguage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
ListItem li=new ListItem("Enlish","en-US");
this.DropDownList1 .Items .Add(li);
li=new ListItem("中国","zh-CN");
this.DropDownList1 .Items .Add(li);
li=new ListItem("French","fr-FR");
this.DropDownList1 .Items .Add(li);
}
// Request.UserLanguages[0].ToString();
ResourceManager LocRM =new ResourceManager( "SkinTest.Resource",typeof(LoginLanguage).Assembly);
注意这里是namespace.加资源文件名(Resource.en-US.resx中的Resource
string lang=DropDownList1.SelectedValue ;
if (lang ==null) lang="en-US";
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
// Sets the UI culture to French (France)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
this.Label1 .Text = LocRM.GetString("user");
this.Label2 .Text = LocRM.GetString("password");
this.Button1 .Text = LocRM.GetString("login");
}
html
<HTML>
<HEAD>
<title>LoginLanguage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 352px; POSITION: absolute; TOP: 160px" runat="server"
Width="96px">用户</asp:Label>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 102; LEFT: 552px; POSITION: absolute; TOP: 80px"
runat="server" AutoPostBack="True"></asp:DropDownList>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 480px; POSITION: absolute; TOP: 160px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox2" style="Z-INDEX: 104; LEFT: 480px; POSITION: absolute; TOP: 208px"
runat="server"></asp:TextBox>
<asp:Label id="Label2" style="Z-INDEX: 105; LEFT: 360px; POSITION: absolute; TOP: 200px" runat="server"
Width="80px">密码</asp:Label>
<asp:Button id="Button1" style="Z-INDEX: 106; LEFT: 480px; POSITION: absolute; TOP: 280px" runat="server"
Text="登录"></asp:Button>
</form>
</body>
</HTML>
在project中加三个资源文件
Resource.en-US.resx
Resource.fr-FR.resx
Resource.zh-CN.resx
内宾为
<data name="login">
<value>login</value>
</data>
<data name="password">
<value>login</value>
</data>
<data name="user">
<value>login</value>
</data>
<data name="login">
<value>登录</value>
</data>
<data name="password">
<value>密码</value>
</data>
<data name="user">
<value>用户</value>
</data>
<data name="login">
<value>xxxx</value>
</data>
<data name="password">
<value>yyyyyyy</value>
</data>
<data name="user">
<value>zzzzzz</value>
</data>
#5
这就是资源文件,网上这些资料很多
#6
没仔细研究过资源文件,不会