See the online implementation of real-time switching, feeling really tired ah! Write Yourself a bar! Boast: simple, elegant, efficient. If there's a better way, you can tell me.
Implementation is the way it is localized in C # itself ..... For example, you have implemented two languages on C # without problems.
1. Language Manager
public enum Languageenum
{
LANGUAGECN,
Languageen,
}
Class Managelanguage
{
public static Managelanguage Instance = new Managelanguage ();
ArrayList objectList = new ArrayList ();
<summary>
Register form
</summary>
<param name= "Item" ></param>
public void Regobject (Formbase item)
{
if (objectlist.contains (item) = TRUE)
{
Objectlist.add (item);
}
}
<summary>
Set Language
</summary>
<param name= "LG" > Language category </param>
public void SetLanguage (languageenum LG)
{
Switch (LG)
{
Case LANGUAGEENUM.LANGUAGECN:
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo ("ZH-CN");
Callbacklanguage ();
Break
Case Languageenum.languageen:
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo ("EN");
Callbacklanguage ();
Break
}
}
<summary>
Traverse a registered form and switch languages
</summary>
void Callbacklanguage ()
{
Traverse all the form to toggle its language
foreach (formbase form in objectList)
{
Form. Language ();
}
}
}
2. Language Switching interface
public partial class Formbase:form
{
Public Formbase ()
{
InitializeComponent ();
ManageLanguage.Instance.RegObject (this);
}
<summary>
Interface for language switching
</summary>
public virtual void Language ()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager (this . GetType ());
ArrayList list = new ArrayList ();
FindControls (list, this);
This. Text = resources. GetString ("$this. Text ");
foreach (Control ctl in list)
{
Resources. Applyresources (CTL, ctl. Name);
}
}
<summary>
To put a localized control into the list
</summary>
<param name= "List" ></param>
<param name= "CTL" ></param>
private void FindControls (ArrayList list, Control ctl)
{
Containers cannot be localized
if (CTL is ContainerControl)
{
MessageBox.Show (ctl. Name);
}
Else
{
List. ADD (CTL);
}
if (CTL. HasChildren)
{
foreach (Control c in CTL.) Controls)
{
if (c is Form)
{
}
Else
{
FindControls (list, c);
}
}
}
}
}
3. When you use it, just inherit it.
Public partial class Formmain:formbase, Icaseview
{
}
Implementation of C # Multi-language real-time switching