1.App.config 文件中定义
<!--记忆语言-->
<appSettings>
<add key="languageRemember" value="2052" />
</appSettings>
2.关闭时保存本次登机的语言选择
// 记忆退出时的语言类型
Communication.ChangeConfiguration("languageRemember", Common.Common.CurrentLcid.ToString());
#region 方法:更改配置文件 /// <summary> /// 更改配置文件 /// </summary> /// <param name="keyName">节点名</param> /// <param name="Value">节点取值</param> public static void ChangeConfiguration(string keyName,string Value) { //读取程序集的配置文件 string assemblyConfigFile = Assembly.GetEntryAssembly().Location; string appDomainConfigFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //获取appSettings节点 AppSettingsSection appSettings = (AppSettingsSection)config.GetSection("appSettings"); //删除name,然后添加新值 appSettings.Settings.Remove(keyName); appSettings.Settings.Add(keyName, Value); //保存配置文件 config.Save(); } #endregion
3.在主程序构造函数中初始化上次的语言
ConfigurationManager.RefreshSection("appSettings");
string i = ConfigurationManager.AppSettings["languageRemember"];
Common.Common.CurrentLcid = int.Parse(i);