在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
先赋上相关读取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文件第一行必须是空格,否则读不出来哦!!! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论