zoukankan      html  css  js  c++  java
  • C# 读取ini文件,读不出来原因

    先赋上相关读取ini文件代码

    public class INIHelper
        {
            public string inipath;
            [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 INIHelper(string INIPath)
            {
                inipath = INIPath;
            }
    
            public void set(string Section, string Key, string Value)
            {
                WritePrivateProfileString(Section, Key, Value, this.inipath);
            }
            /// <summary> 
            /// 读出INI文件 
            /// </summary> 
            /// <param name="Section">项目名称(如 [TypeName] )</param> 
            /// <param name="Key">键</param> 
            public string ReadInivalue(string Section, string Key)
            {
                StringBuilder temp = new StringBuilder(500);
                int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.inipath);
                return temp.ToString();
            }
            /// <summary> 
            /// 验证文件是否存在 
            /// </summary> 
            /// <returns>布尔值</returns> 
            public bool ExistINIFile()
            {
                return File.Exists(inipath);
            }
    
    
            
        }
    

      调用以上方法的代码

    INIHelper iniHelper = new INIHelper(Application.StartupPath + "\Level.ini");
    private void ConfigureShowHighFrm_Load(object sender, EventArgs e)
            {
                if (iniHelper.ReadInivalue("config", "high") == "1")
                    checkBox1.Checked = true;
                else
                    checkBox1.Checked = false;
    
                if (iniHelper.ReadInivalue("config", "hit") == "1")
                    checkBox2.Checked = true;
                else
                    checkBox2.Checked = false;
    
                if (iniHelper.ReadInivalue("config", "low") == "1")
                    checkBox3.Checked = true;
                else
                    checkBox3.Checked = false;
            }
    

      然后再看ini文件截图

    不知道看到没有这个图片,这个就是ini文件第一行必须是空格,否则读不出来哦!!!

  • 相关阅读:
    http协议的状态码——400,401,403,404,500,502,503,301,302等常见网页错误代码
    JS中的动态合集与静态合集
    对联
    诗词
    文言文
    Youth Is Not a Time of Life
    JS探秘——那些你理解存在偏差的问题
    JS中的加号+运算符详解
    支持HTTP2协议
    银行卡信息查询接口
  • 原文地址:https://www.cnblogs.com/Anders888/p/3573104.html
Copyright © 2011-2022 走看看