System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(LANGUAGE_CODE)
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE")
private void SwitchLanguage(string language_code)
{
bool bWasMaximized=(this.WindowState==FormWindowState.Maximized);
this.WindowState=FormWindowState.Normal;
// clear controls
Controls.Clear();
// Change current language
if (language_code=="en")
{
System.Threading.Thread.CurrentThread.CurrentUICulture =
System.Globalization.CultureInfo.InvariantCulture;
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new
System.Globalization.CultureInfo(language_code);
}
// Populate components
InitializeComponent();
// Initialize UI dynamically calling the Load event handler of the Form
// In this case the Load event handler of the form is MyForm_Load
MyForm_Load(null,null);
this.WindowState=FormWindowState.Normal;
this.WindowState=FormWindowState.Maximized;
if (!bWasMaximized)
this.WindowState=FormWindowState.Normal;
this.Refresh();
this.CenterToScreen();
}
public static System.Resources.ResourceManager rm=null;
TranslateHelper.rm = new ResourceManager("MyNamespace.Resource1", this.GetType().Assembly);
"Resource1" is the name of the resources files class that we use in this example and if we are going to use another
name for the resources file we have to substitute it with the new name. The same also with "MyNamespace" which is the default namespace of the project.
public static string TranslateString(string original_string)
{
try
{
string translated_string = rm.GetString(original_string);
if (translated_string == null)
{
return original_string;
}
else
{
return translated_string;
}
}
catch
{
return original_string;
}
}
MessageBox.Show(TranslateHelper.TranslateString("Please specify the name of the product"));
public static void ShowMessageBox(string message)
{
MessageBox.Show(TranslateHelper.TranslateString(message));
}
PictureBox1.Image = (System.Drawing.Image)TranslateHelper.rm.GetObject("MyImage");