winform读写.ini文件的知识
更新时间:2013/12/9 点击:1720次
1、在头部引用
- [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);
2、写入.ini
- WritePrivateProfileString("Setup","UserName",userno.Text,Application.StartupPath+"\\mcs.ini");
3、读取.ini
- StringBuilder temp = new StringBuilder(255);
- int i = GetPrivateProfileString("Setup","UserName","",temp,255, Application.StartupPath+"\\mcs.ini");
- userno.Text = temp.ToString();