using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Windows.Forms; namespace Xylem.Common.Utils.UiLanguageControl { /// /// Change language at runtime /// /// /// - Initial based on code example from stackoverflow /// public static class ControlExtensions { /// /// Change language at runtime /// /// /// - Initial based on code example: /// https://stackoverflow.com/questions/52178064/winforms-localization-how-to-change-the-language-of-a-menu. /// public static IEnumerable AllControls(this Control control) { foreach (Control c in control.Controls) { yield return c; foreach (Control child in c.Controls) yield return child; } } /// /// Update all visual elements after language change /// /// /// - Initial based on code example: /// https://stackoverflow.com/questions/7556367/how-do-i-change-the-culture-of-a-winforms-application-at-runtime /// public static void ChangeControlText(ComponentResourceManager resources, IEnumerable controls) { foreach (Control ctl in controls) { resources.ApplyResources(ctl, ctl.Name); ChangeControlText(resources, ctl.Controls); } } } }