先赋上相关读取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文件第一行必须是空格,否则读不出来哦!!!

C# 读取ini文件,读不出来原因的更多相关文章

  1. C#读取ini文件的方法

    最近项目用到ini文件,读取ini文件,方法如下: using System; using System.Collections.Generic; using System.Linq; using S ...

  2. C# 通过api函数GetPrivateProfileString读取ini文件,取不到值

    通过api函数GetPrivateProfileString读取ini文件,取不到值,测试了好长时间,都不行 确认程序,ini文件都没有错误的情况,最后发现是ini文件编码的原因. 将ini文件的编码 ...

  3. C# 读取ini文件 百度问问学习文档

    C# 读取ini文件 10 有多个section,现想读取整个ini文件和指定section下所有内容 补充: 发布答案可以,请对准题目啊,我不要指定节点的内容,我知道!我要的是读取指定区域的内容,假 ...

  4. Python基础之读取ini文件

    基本使用方法 第一步:准备一份INI文件.如test1.ini [ITEMS] item1=1 item2=2 item3=3 item4=4 [ITEM1] test1=aaa [ITEM2] te ...

  5. VS VC 读取 INI文件

    1.获取应程序同极目录下的config.ini路劲 void GetConfigFilePath(char *path,int len, char *file) { char module[256] ...

  6. python中configparser模块读取ini文件

    python中configparser模块读取ini文件 ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(se ...

  7. bat 读取 ini 文件

    bat 读取 ini 文件 参考链接:https://stackoverflow.com/questions/2866117/windows-batch-script-to-read-an-ini-f ...

  8. java读取ini文件

    ini工具类; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import j ...

  9. c#读取INI文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

随机推荐

  1. Delphi StringGrid控件的用法

    Delphi StringGrid控件 组件名称:StringGrid         ●固定行及固定列:  StringGrid.FixedCols:=固定行之数;  StringGrid.Fixe ...

  2. Vue中 等待DOM或者数据完成 在执行 --this.$nextTick()

    虽然 Vue.js 通常鼓励开发人员沿着“数据驱动”的方式思考,避免直接接触 DOM,但是有时我们确实要这么做.比如一个新闻滚动的列表项.如果在这里需要操作dom, 应该是等待 Vue 完成更新 DO ...

  3. Vue.js基础(一)

      Vue.js的雏形: 数据绑定: 1,单向   {{输出}} 数据=>视图 2,双向   v-model              数据<=>视图 3,{{*msg}} 数据只绑 ...

  4. embsysregview 0.26 无法安装的解决方法。

    最近看到一个比较好的 eclipse 插件:embsysregview,于是想装起来用用看.结果安装过程出错,4个 jar 的包下载不下来,并且通过本地安装的方法也不行. 后来终于找到作者的回复,作者 ...

  5. JSP 调用java 常量 枚举

    JAVA:public enum ReimStatus { UNCONFIRMED ("118001"), //未确认 DISPATCH_VERIFY("118002&q ...

  6. spring 之 init-method & InitializingBean

     init-method  是bean (第一次)实例化的时候被调用的. 先看个异常: INFO: Overriding bean definition ; dependencyCheck=; aut ...

  7. 键值对操作 之 combineByKey

    combineByKey( createCombiner,mergeValue,mergeCombiners,partitioner) combineByKey() 是最为常用的基于键进行聚合的函数. ...

  8. 用JQuery实现简单的菜单隐藏于切换

    <锋利的JQuery>第一个demo<!DOCTYPE html> <html> <head> <meta charset="UTF-8 ...

  9. Flex Iris效果放大或缩小组件演示

    Iris效果通过扩展或收缩集中在目标上的矩形遮罩为效果目标设置动画.该效果可以从目标的中心放大遮罩来显示目标,也可以向中心收缩遮罩来隐藏目标.演示: 源码如下: <?xml version=&q ...

  10. 04.给linux用户添加sudo权限

    linux给用户添加sudo权限: 有时候,linux下面运行sudo命令,会提示类似: xxxis not in the sudoers file.  This incident will be r ...