[Section1] KeyWord1 = Valuel KeyWord2 = Value2 …… [Section2] KeyWord3 = Value3 KeyWord4 = Value4 |
[ 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 ) ; |
private void button2_Click ( object sender , System.EventArgs e ) { string FileName = textBox1.Text ; string section = textBox2.Text ; string key = textBox3.Text ; string keyValue = textBox4.Text ; WritePrivateProfileString ( section , key , keyValue , FileName ) ; MessageBox.Show ( "成功写入INI文件!" , "信息" ) ; } |
private void button3_Click ( object sender , System.EventArgs e ) { StringBuilder temp = new StringBuilder ( 255 ) ; string FileName = textBox1.Text ; string section = textBox2.Text ; string key = textBox3.Text ; int i = GetPrivateProfileString ( section , key ,"无法读取对应数值!", temp , 255 , FileName ) ; //显示读取的数值 textBox4.Text = temp.ToString ( ) ; } |