先赋上相关读取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. cocos设置 相机矩阵和投影矩阵 源码浅析

    在cocos中,最后设置视口大小,相机矩阵,裁剪矩阵是在setProjection方法中,源码如下: void Director::setProjection(Projection projectio ...

  2. KVM总结-KVM性能优化之CPU优化

    前言 任何平台根据场景的不同,都有相应的优化.不一样的硬件环境.网络环境,同样的一个平台,它跑出的效果也肯定不一样.就好比一辆法拉利,在高速公路里跑跟乡村街道跑,速度和激情肯定不同… 所以,我们做运维 ...

  3. Linux性能优化 第七章 性能工具:网络

    7.1 网络I/O介绍 Linux和其他主流操作系统中的网络流量被抽象为一系列的硬件和软件层次. 链路层,也就是最低的一层,包含网络硬件,如以太网设备.在传送网络流量时,这一层并不区分流量类型,而仅仅 ...

  4. WPF简单实用方法(持续更新)

    1:点击退出提示框 MessageBoxResult result = MessageBox.Show("你真的要退出吗?", "", MessageBoxBu ...

  5. 《C++数据结构-快速拾遗》 基础常识

    1.命名空间函数 namespace wjy { void print() { cout<<"; } int load(int num) { return num; } } us ...

  6. Linux NTP

    1.Server 2.QuickStart last 1.Server 0.cn.pool.ntp.org 1.cn.pool.ntp.org 2.cn.pool.ntp.org 3.cn.pool. ...

  7. [UGUI]图文混排(五):添加下划线

    0.下划线标签 标签格式:<material=underline c=#ffffff h=1 n=*** p=***>blablabla...</material> mater ...

  8. 1.1使用java数组,并开始封装我们自己的数组

    今天感冒了,全身酸软无力,啥样不想做,就来学习吧,此节我们从初步使用java中提供的数组,然后分析相关情况,过渡到封装我们自己的数组. 一.我们先来感受一下java提供的数组,以整型数组(int[]) ...

  9. [多线程]线程基础(对象锁、class锁、同步、异步)

    synchronized.volatile.ReentrantLock.concurrent 线程安全:当多个线程访问某一个类(对象或方法)时,这个类始终都能表现出正确的行为,那么这个类(对象或方法) ...

  10. linux base shell 基础语法2

    转载 http://blog.csdn.net/aggrelxf/article/details/8263110 单引 双引 反引用[] [[]] 将命令的输出读入一个变量中,可以将它放入双引号中,即 ...