Winfrom 程式執行中,切換語系。
我想做的是在開啟程式後,
再切換語系,
所以會用到Control的方式,
再去Apply原本的form。
**使用此範例前要先設定好不同語系的資源檔
範例:
private void button2_Click(object sender, EventArgs e)
{
CreateManager(this, "zh-TW");
}
private void button3_Click(object sender, EventArgs e)
{
CreateManager(this, "en");
}
public void CreateManager(Control Control, string Language)
{
CultureInfo Cul= new System.Globalization.CultureInfo(Language);
Thread.CurrentThread.CurrentUICulture = Cul;
this._ResourceManager = new ComponentResourceManager(Control.GetType());
this._ResourceManager.ApplyResources(Control, "$this");
this.Apply(Control);
}
public void Apply(Control control)
{
foreach (Control ctrl in control.Controls)
{
this._ResourceManager.ApplyResources(ctrl, ctrl.Name);
if (ctrl.HasChildren)
{
Apply(ctrl);
}
}
}
}
自我LV~