我在form1里面放上一个 comboBox1控件
在通一个目录下,建一个 config.intconfig.int里面写上
[system]
apptitle=管理系统
version=2.0.0
AreaID=FJ_福建;GX_广西;form1 中comboBox1 就会显示 
FJ_福建
GX_广西按照;截取的,只要我在config.ini中的Areaid添加信息
form1 中comboBox1就会显示出来,如:config.int里面写上
[system]
apptitle=管理系统
version=2.0.0
AreaID=FJ_福建;GX_广西;GD_广东;form1 中comboBox1 就会显示 
FJ_福建
GX_广西
GD_广东由于我文件不多,(但也不是固定的,要随时添加,或者删除),不用xml配置,只要用.ini文件配置就好了.请教下,在C#中要怎样写........

解决方案 »

  1.   

    为什么要用ini?
    .net里面都是用xml
      

  2.   

    http://community.csdn.net/Expert/topic/3158/3158361.xml?temp=.5364191http://community.csdn.net/Expert/topic/3864/3864801.xml?temp=.6122553http://www.codeproject.com/csharp/cs_ini.asp就是调用api
      

  3.   

    使用API读取INI文件 
     
    INI文件[测试]用户=AINA 使用的API函数GetPrivateProfileString  [System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint="GetPrivateProfileString")]
      public static extern int GetPrivateProfileString (
                                                     string lpApplicationName,
                                                     string lpKeyName,
                                                     string lpDefault,
                                                     StringBuilder lpReturnedString,
                                                     int nSize,
                    string lpFileName
                    );  //  lpApplicationName -  String,欲在其中查找条目的小节名称。这个字串不区分大小写。如设为vbNullString,就在lpReturnedString缓冲区内装载这个ini文件所有小节的列表
      //
      //  lpKeyName ------  String,欲获取的项名或条目名。这个字串不区分大小写。如设为vbNullString,就在lpReturnedString缓冲区内装载指定小节所有项的列表
      //
      //  lpDefault ------  String,指定的条目没有找到时返回的默认值。可设为空("")
      //
      //  lpReturnedString -  StringBuilder,指定一个字串缓冲区,长度至少为nSize
      //
      //  nSize ----------  Long,指定装载到lpReturnedString缓冲区的最大字符数量
      //
      //  lpFileName -----  String,初始化文件的名字。如没有指定一个完整路径名,windows就在Windows目录中查找文件
       StringBuilder temp = new StringBuilder(255);
       int i = GetPrivateProfileString("测试","用户","",temp,255,"INI文件路径");
       MessageBox.Show(temp.ToString());
     
      

  4.   

    把读出来的数据用split分开,然后绑定到combobox就可以了--------------------------
    楼上的,ini有ini的好,xml有xml的好,是不一样的,看用在什么地方了
      

  5.   

    Try this:
    http://www.codeproject.com/csharp/ReadWriteXmlIni.asp
      

  6.   

    to:icemaninicesoft(远翔) (
     
    谢谢to: zhouweiwansui(三区 勇士岛 人类战士) 
    因为数据很少.最多不超过30个,所以在.ini里面写比较方便,添加,删除什么的
    to: realplm(--) ,lovefootball(蟑螂)
    谢谢,我试着测试下
      

  7.   

    写ini文件
    [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
    读ini文件
    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);
      

  8.   

    WritePrivateProfileString
    GetPrivateProfileString
    两个API
      

  9.   

    .NET对ini支持不好,都用xml
    前些日子我自己写过一个全面支持ini文件读写的类,主要基于正则表达式,提供很多方法,包括得到具体的key的value。
      

  10.   

    把下面的代码改动一下,就可以在你的程序中使用 
    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Text;namespace Sx_Mdi
    {/// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class IniFile
    {
    //文件INI名称
    public string Path;////声明读写INI文件的API函数 
    [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);
    //类的构造函数,传递INI文件名
    public IniFile(string inipath)
    {
    //
    // TODO: Add constructor logic here
    //
    Path = inipath;
    }//写INI文件
    public void IniWriteValue(string Section,string Key,string Value)
    {
    WritePrivateProfileString(Section,Key,Value,this.Path);}//读取INI文件指定
    public string IniReadValue(string Section,string Key)
    {
    StringBuilder temp = new StringBuilder(255);
    int i = GetPrivateProfileString(Section,Key,"",temp,255,this.Path);
    return temp.ToString();}
    }
    }操作范例:public static SqlConnection MyConnection()
    {
    string sPath;
    string ServerName,userId,sPwd,DataName;sPath = GetPath();
    IniFile ini = new IniFile(sPath);
    ServerName = ini.IniReadValue ("Database","server");
    userId = ini.IniReadValue ("Database","uid");
    sPwd = ini.IniReadValue ("Database","pwd");
    DataName = ini.IniReadValue ("Database","database");
    string strSql = "server =" + ServerName+";uid ="+ userId +";pwd =;database ="+ DataName;
        SqlConnection myConn=new SqlConnection(strSql);
        return myConn; 
    }