zoukankan      html  css  js  c++  java
  • C#中的语言记忆功能

    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
    View Code

    3.在主程序构造函数中初始化上次的语言

    ConfigurationManager.RefreshSection("appSettings");
    string i = ConfigurationManager.AppSettings["languageRemember"];
    Common.Common.CurrentLcid = int.Parse(i);

  • 相关阅读:
    326. Power of Three
    python实现Excel删除特定行、拷贝指定行操作
    283. Move Zeroes
    268. Missing Number
    263. Ugly Number
    258. Add Digits
    257. Binary Tree Paths
    二叉树的创建,递归前序、中序、后序遍历以及队列实现层遍历
    242. Valid Anagram
    237. Delete Node in a Linked List
  • 原文地址:https://www.cnblogs.com/mamaxiaoling/p/8417173.html
Copyright © 2011-2022 走看看