예제 #1
0
 /// <summary>
 /// 反序列化XML字符串为对象
 /// </summary>
 /// <param name="xmlSource"></param>
 /// <returns></returns>
 public static CLanguage Deserialize(string filename)
 {
     CLanguage obj = new CLanguage();
     if (filename.Trim() == "") return obj;
     try
     {
         XmlSerializer x = new XmlSerializer(typeof(CLanguage), new Type[] { typeof(LanguageItem) });
         // Create a TextReader to read the file.
         FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
         TextReader reader = new StreamReader(fs);
         obj = (CLanguage)x.Deserialize(reader);
         reader.Close();
         fs.Close();
         fs.Dispose();
     }
     catch
     {
         return null;
     }
     return obj;
 }
예제 #2
0
        public static bool SetLanguage(string lang, Form frm, ToolTip tip = null)
        {
            _language = lang;
            string languageCfg = AppRootPath + "\\Language\\" + lang + ".xml";
            CLanguage langGetNow = CLanguage.Deserialize(languageCfg);

            if (langGetNow == null)
            {
                MessageBox.Show(CDefines.GetDStr("MSG_NO_LANGUAGE"));
                return false;
            }
            else
            {
                langInst = langGetNow;
                foreach (LanguageForm langForm in CDefines.langInst.Forms)
                {
                    if (langForm.Name == frm.Name)
                    {
                        foreach (LanguageItem item in langForm.Controls)
                        {
                            ChangeControl(item.name, item.text, item.tooltip, frm, tip);
                        }
                        foreach (LanguageItem item in langForm.Menus)
                        {
                            ChangeMenu(item.name, item.text, item.tooltip, frm);
                        }
                        foreach (LanguageItem item in langForm.Toolbars)
                        {
                            ChangeToolbar(item.name, item.text, item.tooltip, frm);
                        }
                        foreach (LanguageListView langView in langForm.ListViews)
                        {
                            Control[] ctrls = frm.Controls.Find(langView.Name, true);
                            if (ctrls != null && ctrls.Length > 0)
                            {
                                ListView listViewFind = ctrls[0] as ListView;
                                foreach (ColumnHeader col in listViewFind.Columns)
                                {
                                    if (langView.Columns[col.Index] != null)
                                        col.Text = langView.Columns[col.Index].text;
                                }
                                foreach (ListViewGroup grp in listViewFind.Groups)
                                {
                                    grp.Header = FindGroupInListView(grp.Name, langView.Groups);
                                }
                            }
                        }
                    }
                }

                return true;
            }
        }