如何加载默认UI控件文本? [英] How to load Default UI control Text?
本文介绍了如何加载默认UI控件文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的所有人,
我已将Localizable设为"True",我的配置中有两种语言。
I have enable the Localizable to "True", and there are two kinds of language in my configuration.
一个是默认,控件上的文字是英文,另一个是繁体中文(zh-TW),
One is Default, and text on the controls are in English, the other are in Traditional Chinese(zh-TW),
zh-TW的文本可以由以下方式,
The text of zh-TW can be load by the following way,
如何加载默认用户界面?
谢谢和致以诚挚的问候,
Thanks and Best regards,
E-John
推荐答案
亲爱的所有,
我找到了一种方法,如下所示
I found a way to do so, like below
有没有更好的方法,比如简化代码的反射?
private void ChangeControlTextLanguage(string language)
{
string lang = "(Default)";
if (language == "中文")
{
lang = "zh-TW";
ComponentResourceManager resourcesss = new ComponentResourceManager(typeof(LoginForm));
CultureInfo cult = new CultureInfo(lang);
// Change Form Text
this.Text = resourcesss.GetString("
this.Text",cult);
//所有按钮
foreach(控制b in this.Controls)
{
if(b is Button)
resourcesss.ApplyResources((Button) )b,((按钮)b).Name,cult);
}
//每个TabPage上的所有控件
foreach(在this.tabControl1.Controls中控制t)
{
TabPage tabPage =(TabPage)t;
foreach(tabPage.Controls中的控制项)
{
if(item is Label)
{
resourcesss.ApplyResources((Label)item, ((标签)项目。),邪教);
}
if(item is CheckBox)
{
resourcesss.ApplyResources((CheckBox)item,((CheckBox)item).Name,cult);
}
}
}
}
else
{
ComponentResourceManager resourcesss = new ComponentResourceManager(typeof(LoginForm));
//更改表格文本
this.Text = resourcesss.GetString("
this.Text", cult); // All buttons foreach (Control b in this.Controls) { if (b is Button) resourcesss.ApplyResources((Button)b, ((Button)b).Name, cult); } // All controls on each TabPage foreach (Control t in this.tabControl1.Controls) { TabPage tabPage = (TabPage)t; foreach (Control item in tabPage.Controls) { if (item is Label) { resourcesss.ApplyResources((Label)item, ((Label)item).Name, cult); } if (item is CheckBox) { resourcesss.ApplyResources((CheckBox)item, ((CheckBox)item).Name, cult); } } } } else { ComponentResourceManager resourcesss = new ComponentResourceManager(typeof(LoginForm)); // Change Form Text this.Text = resourcesss.GetString("
this.Text");
//所有按钮
foreach(控制b in this.Controls)
{
if(b is Button)
resourcesss.ApplyResources((Button) )b,((按钮)b).Name);
}
//每个TabPage上的所有控件
foreach(在this.tabControl1.Controls中控制t)
{
TabPage tabPage =(TabPage)t;
foreach(tabPage.Controls中的控制项)
{
if(item is Label)
{
resourcesss.ApplyResources((Label)item, ((标签)项)请将.Name);
}
if(item is CheckBox)
{
resourcesss.ApplyResources((CheckBox)item,((CheckBox)item).Name);
}
}
}
}
}
this.Text"); // All buttons foreach (Control b in this.Controls) { if (b is Button) resourcesss.ApplyResources((Button)b, ((Button)b).Name); } // All controls on each TabPage foreach (Control t in this.tabControl1.Controls) { TabPage tabPage = (TabPage)t; foreach (Control item in tabPage.Controls) { if (item is Label) { resourcesss.ApplyResources((Label)item, ((Label)item).Name); } if (item is CheckBox) { resourcesss.ApplyResources((CheckBox)item, ((CheckBox)item).Name); } } } } }
谢谢和最诚挚的问候,
E-John
这篇关于如何加载默认UI控件文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文