先赋上相关读取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. scala语法在spark withScope上的应用

    withSpout在spark中是用来做DAG可视化的,它在代码里的用法如下(以map为例,spark 2.0.0版本) def map[U: ClassTag](f: T => U): RDD ...

  2. Hadoop简介与分布式安装

    Hadoop的基本概念和分布式安装: Hadoop 简介 Hadoop 是Apache Lucene创始人道格·卡丁(Doug Cutting)创建的,Lucene是一个应用广泛的文本搜索库,Hado ...

  3. jQuery实现点击控制左右两边元素挤压显示效果

    该功能实现的是:分左.右两边布局,左边div默认展开,左边div中有一个元素,点击实现左边div隐藏,右边div挤压过来:再点击实现左边显示,右边挤过去. 一.HTML代码: <div clas ...

  4. liinux安装 mysql 及主从复制

    mariadb其实就是mysqlmysql已经被oracle收购,它即将闭源,马上要开始收费了因此还想免费试用开源的数据库mysql,就在centos7上,将mysql分支为mariadb 安装mar ...

  5. python之格式化输出(3种方式)

    python3.6后支持3种格式化输出方式,其中前两种为%-formatting及str.format ,第三种即为 f-string. 1.%-formatting 据传该格式化方法源于C.. &g ...

  6. BZOJ4195 luoguP1955 NOI2015D1T1 程序自动分析

    题意:给定n个(xi = xj) 或 (xi != xj) 的条件,问是否可能成立 BZOJ链接:http://www.lydsy.com/JudgeOnline/problem.php?id=419 ...

  7. 【Java】边框总结

    [Java]边框总结 Table of Contents 1 例子代码与结果 2 javax.swing.border 3 BorderFactory 4 LineBorder 5 MatteBord ...

  8. python生成器异步使用

    import dis,time # 反汇编 import threading def request(): print('start request') v = yield print(v) def ...

  9. Check Kernel version of J2EE Engine

    1912674 - How to check kernel version of an AS Java Two types of the kernel are in SAP NetWeaver Jav ...

  10. 22.Windows及linux下gerapy使用

    Windows安装 gerapy1.pip install gerapy2.gerapy init 3.cd gerapy(切换目录到gerapy文件夹)4.gerapy migrate5.gerap ...