先赋上相关读取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. REST framwork之认证,权限与频率

    认证组件 局部视图认证 在app01.service.auth.py: class Authentication(BaseAuthentication): def authenticate(self, ...

  2. tomcat7.0安装笔记

    1. 解压,新增系统环境变量CATALINA_HOME,值为tomcat所在目录,如E: tomcat7.0 PS:安装JAVA时没有配置系统变量JAVA_HOME,导致报错无法启动tomcat,新建 ...

  3. Windows向虚拟机Linux传输文件方法

    在Windows中装了个centOS,进行文件操作时,把mv写成了rm,然后就悲剧了.. 赶紧从网上找来文件的具体内容,然后由Windows向Linux挂载共享文件夹. 具体做法: 在Windows中 ...

  4. Java中对List集合的常用操作(转)

    list中添加,获取,删除元素: list中是否包含某个元素: list中根据索引将元素数值改变(替换): list中查看(判断)元素的索引: 根据元素索引位置进行的判断: 利用list中索引位置重新 ...

  5. c# 中实用包,实用dll。

    Aspose.cell:用与操作Excel,生成,导入导出等. ICSharpCode.SharpZipLib.dll:用户压缩及解压ZIP包,根据需要也可以加密.

  6. ace admin

    .svg             image/svg+xml.woff            application/x-font-woff.woff2          application/x- ...

  7. 【转】不联网如何PING通WIN主机和VMWARE

    原文地址:http://www.gqgtpc.com/thread-76838-1-1.html 一般情况下,如果宿主主机的网口连接网线并且能够上网,那么按照VM的默认安装,在VM-Settings- ...

  8. maven 插件深入了解

    http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin http://www.infoq.com/cn/news/2011/05/xxb-mav ...

  9. 1. orcle 创建可扩展表空间

    1.创建表空间 a). create tablespace tablespacename datafile 'D:\tablespace\tablespacename.dbf' size 200m a ...

  10. twisted的DelayedCall

    >>> l=[,,,,] >>> del l[:]#只是删除列表的部分元素,列表仍然存在 >>> l [, ] #reactor循环执行的函数de ...