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();