Witam,
Utworzyłem sobie w aplikacji resource.pl.resx w którym chce wpisywać np. nazwakontrolki.Text = polska nazwa. A designerze mam podane angielskie nazwy, zapisywane w resources.resx. Jak mogę teraz używać tego w aplikacji, żeby przy kliknięciu w button zmieniał mi język z polskiego na angielski i odwrotnie?
0
0
Udało się to rozwiązać w taki sposób:
private void btnPolandLanguage_Click(object sender, EventArgs e)
{
if (Thread.CurrentThread.CurrentUICulture.Name == "pl-PL")
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
ComponentResourceManager resources = new ComponentResourceManager(typeof(PasswordManager));
resources.ApplyResources(this, "$this");
applyResources(resources, this.Controls);
}
else
{
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pl-PL");
ComponentResourceManager resources = new ComponentResourceManager(typeof(PasswordManager));
resources.ApplyResources(this, "$this");
applyResources(resources, this.Controls);
}
textBox1.Text = Thread.CurrentThread.CurrentUICulture.Name;
}
private void applyResources(ComponentResourceManager resources, Control.ControlCollection ctls)
{
foreach (Control ctl in ctls)
{
resources.ApplyResources(ctl, ctl.Name);
applyResources(resources, ctl.Controls);
}
}