visual orden los formularios formulario eventos c# .net winforms localization

c# - orden - ¿Cómo cambio la cultura de una aplicación WinForms en tiempo de ejecución?



eventos de un formulario en visual basic (3)

Creé el programa Windows Form en C #. Tengo algunos problemas con la localización. Tengo archivos de recursos en 2 idiomas (uno es para inglés y otro para francés). Quiero hacer clic en cada botón de idioma y cambiar el idioma en tiempo de ejecución.

Pero cuando hago clic en el botón, no funciona. estoy usando este código

private void btnfrench_Click(object sender, EventArgs e) { getlanguage("fr-FR"); } private void getlanguage(string lan) { foreach (Control c in this.Controls) { ComponentResourceManager cmp = new ComponentResourceManager(typeof(BanksForm)); cmp.ApplyResources(c, c.Name, new CultureInfo(lan)); } }

cualquier pls ayuda en esto ......

Muchas gracias....


Es posible que deba llamar a ApplyResources recursivamente en los controles:

private void btnfrench_Click(object sender, EventArgs e) { ApplyResourceToControl( this, new ComponentResourceManager(typeof(BanksForm)), new CultureInfo("fr-FR")) } private void ApplyResourceToControl( Control control, ComponentResourceManager cmp, CultureInfo cultureInfo) { cmp.ApplyResources(control, control.Name, cultureInfo); foreach (Control child in control.Controls) { ApplyResourceToControl(child, cmp, cultureInfo); } }


Esto funcionó:

private void button1_Click(object sender, EventArgs e) { System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-BE"); ComponentResourceManager resources = new ComponentResourceManager(typeof(Form1)); resources.ApplyResources(this, "$this"); applyResources(resources, this.Controls); } private void applyResources(ComponentResourceManager resources, Control.ControlCollection ctls) { foreach (Control ctl in ctls) { resources.ApplyResources(ctl, ctl.Name); applyResources(resources, ctl.Controls); } }

Tenga cuidado de evitar agregar silbidos como este que nadie usará nunca.


La actualización de CultureInfo en tiempo de ejecución podría restablecer el tamaño del componente. Este código conserva el tamaño y la posición de los controles (aunque seguirá habiendo parpadeos visibles, que al usar SuspendLayout () no pudieron solucionarse)

private void langItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { //I store the language codes in the Tag field of list items var itemClicked = e.ClickedItem; string culture = itemClicked.Tag.ToString().ToLower(); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); ApplyResourceToControl( this, new ComponentResourceManager(typeof(GUI)), new CultureInfo(culture)); } private void ApplyResourceToControl( Control control, ComponentResourceManager cmp, CultureInfo cultureInfo) { foreach (Control child in control.Controls) { //Store current position and size of the control var childSize = child.Size; var childLoc = child.Location; //Apply CultureInfo to child control ApplyResourceToControl(child, cmp, cultureInfo); //Restore position and size child.Location = childLoc; child.Size = childSize; } //Do the same with the parent control var parentSize = control.Size; var parentLoc = control.Location; cmp.ApplyResources(control, control.Name, cultureInfo); control.Location = parentLoc; control.Size = parentSize; }