Hi I have C# windows form with 11 forms. I use language Properties of All forms to design them in 2 language (default and English united state). In my setting form I have 2 radio button and I want when user click on them the languages of all form change. I find 2 example for this but none of them work how to do this?
this is my first try: (not working and Messing up the placement of controls on the form)
private void radioButtonDefault_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentUICulture;
// Reload the form or the controls to apply the new language
this.Controls.Clear();
InitializeComponent();
}
private void radioButtonEnglish_Click(object sender, EventArgs e)
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
// Reload the form or the controls to apply the new language
this.Controls.Clear();
InitializeComponent();
}
this is my Second try: (not run get too many error)
private void radioButtonDefault_Click(object sender, EventArgs e)
{
SwitchToDefaultLanguage();
}
private void radioButtonEnglish_Click(object sender, EventArgs e)
{
SwitchToEnglish();
}
private static void ApplyResources(Control control, string name, CultureInfo culture)
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(control.GetType(), name, culture);
control.Text = resources.GetString("$this.Text");
foreach (Control child in control.Controls)
{
ApplyResources(child, child.Name, culture);
}
}
private void SwitchToDefaultLanguage()
{
this.SuspendLayout();
this.Localizable = true;
this.components = new System.ComponentModel.Container();
// Load the resources for the default language
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingForm));
resources.ApplyResources(this, "$this");
// Apply the resources to all the controls of the form
ApplyResources(this, this.Name, CultureInfo.CurrentUICulture);
this.ResumeLayout(false);
}
private void SwitchToEnglish()
{
this.SuspendLayout();
this.Localizable = true;
this.components = new System.ComponentModel.Container();
// Load the resources for the English language
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingForm));
resources.ApplyResources(this, "$this");
// Apply the resources to all the controls of the form
ApplyResources(this, this.Name, CultureInfo.GetCultureInfo("en-US"));
this.ResumeLayout(false);
}
how can solve my problem? please help?