using System; using System.Collections.Generic; using System.Windows.Forms; namespace Xylem.Common.Utils.UiLanguageControl { /// /// Change language at runtime /// /// /// - Initial based on code example from stackoverflow /// [Serializable] public static class ToolStripExtensions { /// /// 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 AllItems(this ToolStrip toolStrip) { return toolStrip.Items.Flatten(); } /// /// 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 Flatten(this ToolStripItemCollection items) { foreach (ToolStripItem item in items) { if (item is ToolStripDropDownItem) foreach (var subItem in ((ToolStripDropDownItem)item).DropDownItems.Flatten()) yield return subItem; yield return item; } } } }