• C#对config.ini文件进行读取和修改


    C#对config.ini文件进行读取和修改:

    public partial class Patrolcar : Form之后可以加入如下类:

    #region
            public class IniFile
            {
                public string map_length, map_width, maxnum_connect, net_ip;
                public string path;
                [DllImport("kernel32")]
                private static extern long WritePrivateProfileString(string section,
                string key, string val, string filePath);
                [DllImport("kernel32")]
                private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal,
                int size, string filePath);
    
                public IniFile(string INIPath)
                {
                    path = INIPath;
                }
    
                public void getIni()
                {
                    map_length = IniReadValue("setting", "map_length").ToString();
                    map_width = IniReadValue("setting", "map_width").ToString();
                    maxnum_connect = IniReadValue("setting", "maxnum_connect").ToString();
                    net_ip = IniReadValue("setting", "net_ip").ToString();
                }
    
                public void IniWriteValue(string Section, string Key, string Value)
                {
                    WritePrivateProfileString(Section, Key, Value, this.path);
                }
    
                public string IniReadValue(string Section, string Key)
                {
                    StringBuilder temp = new StringBuilder(1024);
                    int i = GetPrivateProfileString(Section, Key, "", temp, 1024, this.path);
                    return temp.ToString();
                }
            }
    
            IniFile dgd_ini = new IniFile(System.IO.Path.Combine(Application.StartupPath, "config.ini"));
            #endregion

    然后在InitializeComponent();语句之后就可以进行函数操作了:

    InitializeComponent();
    dgd_ini.getIni();

    config.ini文件位于...inDebug目录下。

  • 相关阅读:
    c# webapi无法获取Session值问题解决
    深入理解java虚拟机之自动内存管理机制笔记
    数据结构总结1
    疯人院之语言、编码、计算机

    集线器/交换机
    什么是DOM?DOM和JavaScript的关系 [web开发]
    JSON轻量级的数据交换格式
    天问宇宙学第一课
    C++基础知识
  • 原文地址:https://www.cnblogs.com/ming-4/p/12268431.html
Copyright © 2020-2023  润新知