46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Xylem.Common.Utils.UiLanguageControl
|
|
{
|
|
/// <summary>
|
|
/// Change language at runtime
|
|
/// </summary>
|
|
/// <remarks date="2021-Feb-23" author="Thomas Wiedebusch">
|
|
/// - Initial based on code example from stackoverflow
|
|
/// </remarks>
|
|
public static class ToolStripExtensions
|
|
{
|
|
/// <summary>
|
|
/// Change language at runtime
|
|
/// </summary>
|
|
/// <remarks date="2021-Feb-23" author="Thomas Wiedebusch">
|
|
/// - Initial based on code example
|
|
/// https://stackoverflow.com/questions/52178064/winforms-localization-how-to-change-the-language-of-a-menu.
|
|
/// </remarks>
|
|
public static IEnumerable<ToolStripItem> AllItems(this ToolStrip toolStrip)
|
|
{
|
|
return toolStrip.Items.Flatten();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Change language at runtime
|
|
/// </summary>
|
|
/// <remarks date="2021-Feb-23" author="Thomas Wiedebusch">
|
|
/// - Initial based on code example
|
|
/// https://stackoverflow.com/questions/52178064/winforms-localization-how-to-change-the-language-of-a-menu.
|
|
/// </remarks>
|
|
public static IEnumerable<ToolStripItem> 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;
|
|
}
|
|
}
|
|
}
|
|
}
|