mirror of
https://github.com/jie65535/GrasscutterCommandGenerator.git
synced 2025-10-24 20:49:47 +08:00
Open Sources
This commit is contained in:
83
Source/GrasscutterTools/MultiLanguage.cs
Normal file
83
Source/GrasscutterTools/MultiLanguage.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace GrasscutterTools
|
||||
{
|
||||
static class MultiLanguage
|
||||
{
|
||||
|
||||
public static string DefaultLanguage = "zh-CN";
|
||||
|
||||
public static void SetDefaultLanguage(string lang)
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
|
||||
DefaultLanguage = lang;
|
||||
Properties.Settings.Default.DefaultLanguage = lang;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载语言
|
||||
/// </summary>
|
||||
/// <param name="form">加载语言的窗口</param>
|
||||
/// <param name="formType">窗口的类型</param>
|
||||
public static void LoadLanguage(Form form, Type formType)
|
||||
{
|
||||
if (form != null)
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(formType);
|
||||
resources.ApplyResources(form, "$this");
|
||||
Loading(form, resources);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载语言
|
||||
/// </summary>
|
||||
/// <param name="control">控件</param>
|
||||
/// <param name="resources">语言资源</param>
|
||||
private static void Loading(Control control, System.ComponentModel.ComponentResourceManager resources)
|
||||
{
|
||||
if (control is MenuStrip strip)
|
||||
{
|
||||
//将资源与控件对应
|
||||
resources.ApplyResources(control, control.Name);
|
||||
if (strip.Items.Count > 0)
|
||||
{
|
||||
foreach (ToolStripMenuItem c in strip.Items)
|
||||
{
|
||||
//遍历菜单
|
||||
Loading(c, resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Control c in control.Controls)
|
||||
{
|
||||
resources.ApplyResources(c, c.Name);
|
||||
Loading(c, resources);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 遍历菜单
|
||||
/// </summary>
|
||||
/// <param name="item">菜单项</param>
|
||||
/// <param name="resources">语言资源</param>
|
||||
private static void Loading(ToolStripMenuItem item, System.ComponentModel.ComponentResourceManager resources)
|
||||
{
|
||||
if (item is ToolStripMenuItem tsmi)
|
||||
{
|
||||
resources.ApplyResources(item, item.Name);
|
||||
if (tsmi.DropDownItems.Count > 0)
|
||||
{
|
||||
foreach (ToolStripMenuItem c in tsmi.DropDownItems)
|
||||
{
|
||||
Loading(c, resources);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user