/// <summary> /// 获取控件的名称(窗体包含菜单项等) /// </summary> /// <param name="form"></param> public static void GetNames(System.ComponentModel.ComponentCollection component, Form form, String lang, string languageResourceFolder) { //根据用户选择的语言获得表的显示文字 Hashtable table = ReadResource(form.Name, lang, languageResourceFolder); Control.ControlCollection controlNames = form.Controls; //可以在这里设置窗体的一些统一的属性,这样所有的窗体都会应用该设置 // form.KeyPreview = true; // form.MaximizeBox = false; // form.MinimizeBox = false; // form.ControlBox = false; // form.FormBorderStyle = FormBorderStyle.FixedDialog; // form.StartPosition = FormStartPosition.CenterScreen; // form.TopMost = true; // form.KeyDown += new KeyEventHandler(OnEnter); try { if (component != null)//遍历非窗体上的控件(如:右键菜单) { IEnumerator ie = component.GetEnumerator(); while (ie.MoveNext()) { Console.WriteLine(ie.Current.GetType().ToString()); if ((ie.Current as Control) != null) { if (ie.Current.GetType() == typeof(System.Windows.Forms.ContextMenuStrip)) { GetMenustripControls((ie.Current as ContextMenuStrip).Items, table); } } } } //遍历窗体上的控件 SetControlText(form, table, controlNames); } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show(ex.InnerException.Message); } }
public void UpdateComponents(System.ComponentModel.ComponentCollection compCollection) { // Iterate through the Forms context menus... foreach (System.ComponentModel.Component comp in compCollection) { if (comp is System.Windows.Forms.ContextMenuStrip) { System.Windows.Forms.ContextMenuStrip cms = (System.Windows.Forms.ContextMenuStrip)comp; foreach (DataRow dr in _appSettings.Rows) { System.Windows.Forms.ToolStripItem[] tsiArray = cms.Items.Find(dr["app_resource_name"].ToString(), true); if (tsiArray != null && tsiArray.Length > 0) { foreach (System.Windows.Forms.ToolStripItem tsi in tsiArray) { tsi.Text = dr["display_member"].ToString(); } } } } } }
public void UpdateComponents(System.ComponentModel.ComponentCollection compCollection, string formName) { // Set the row filter based on the Form's name and the lang... _appResources.DefaultView.RowFilter = "sys_lang_id=" + _lang.ToString() + " AND form_name='" + formName + "'"; // Iterate through the Forms context menus... foreach (System.ComponentModel.Component comp in compCollection) { if (comp is System.Windows.Forms.ContextMenuStrip) { System.Windows.Forms.ContextMenuStrip cms = (System.Windows.Forms.ContextMenuStrip)comp; foreach (DataRowView drv in _appResources.DefaultView) { System.Windows.Forms.ToolStripItem[] tsiArray = cms.Items.Find(drv["app_resource_name"].ToString(), true); if (tsiArray != null && tsiArray.Length > 0) { foreach (System.Windows.Forms.ToolStripItem tsi in tsiArray) { tsi.Text = drv["display_member"].ToString(); } } } } } }
public void UpdateComponents(System.ComponentModel.ComponentCollection compCollection, string formName) { _appSettings.UpdateComponents(compCollection, formName); }