using Microsoft.VisualBasic.CompilerServices; using System; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.Threading; using System.Windows.Forms; namespace HPG_68D { public class LanguageHelper { [DebuggerNonUserCode] public LanguageHelper() { } public static bool SetLanguage(string languageName, Form frm) { bool flag; try { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(languageName); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(languageName); var res = new ComponentResourceManager(frm.GetType()); res.ApplyResources(frm, "$this"); ApplyResouce(frm, res); flag = true; } catch (Exception ex) { ProjectData.SetProjectError(ex); flag = false; ProjectData.ClearProjectError(); } return flag; } private static void ApplyResouce(Control control, ComponentResourceManager res) { try { foreach (Control control1 in control.Controls) { res.ApplyResources(control1, control1.Name); if (control1 is TabControl) ApplyResouce((TabControl) control1, res); if (control1 is DataGridView) ApplyResouce((DataGridView) control1, res); if (control1.GetType().IsSubclassOf(typeof (ToolStrip))) ApplyResouce((ToolStrip) control1, res); if (control1 is ComboBox) ApplyResouce((ComboBox) control1, res); ApplyResouce(control1, res); } } finally { } } private static void ApplyResouce(ToolStrip toolstrip, ComponentResourceManager resources) { if (toolstrip.Items.Count <= 0) return; try { foreach (ToolStripItem toolStripItem in toolstrip.Items) ApplyResouce(toolStripItem, resources); } finally { } } private static void ApplyResouce(ToolStripItem item, ComponentResourceManager resources) { resources.ApplyResources(item, item.Name); if (!item.GetType().IsSubclassOf(typeof (ToolStripDropDownItem))) return; var stripDropDownItem = (ToolStripDropDownItem) item; if (stripDropDownItem.DropDownItems.Count > 0) { try { foreach (ToolStripItem dropDownItem in stripDropDownItem.DropDownItems) ApplyResouce(dropDownItem, resources); } finally { } } } private static void ApplyResouce(DataGridView datagridview, ComponentResourceManager resources) { if (datagridview.Columns.Count <= 0) return; try { foreach (DataGridViewColumn column in datagridview.Columns) ApplyResouce(column, resources); } finally { } } private static void ApplyResouce(DataGridViewColumn item, ComponentResourceManager resources) { resources.ApplyResources(item, item.Name); } private static void ApplyResouce(ComboBox combobox, ComponentResourceManager resources) { if (combobox.Items.Count <= 0) return; var num = checked (combobox.Items.Count - 1); var index = 0; while (index <= num) { combobox.Items[index] = index == 0 ? resources.GetString(combobox.Name + ".Items") : (object) resources.GetString(combobox.Name + ".Items" + Conversions.ToString(index)); checked { ++index; } } } private static void ApplyResouce(TabControl tabcontrol, ComponentResourceManager resources) { if (tabcontrol.TabCount <= 0) return; resources.ApplyResources(tabcontrol, tabcontrol.Name); try { foreach (TabPage tabPage in tabcontrol.TabPages) ApplyResouce(tabPage, resources); } finally { } } private static void ApplyResouce(TabPage item, ComponentResourceManager resources) { resources.ApplyResources(item, item.Name); } } }