C # language is still more common things, here we mainly introduce C # to INI file operations, including the introduction of the INI file to write operations and so on.
C # operations on INI file
The INI file is written and is implemented through the "click" Event of the component Button2. One thing to note here is that when you invoke WritePrivateProfileString () to write to the INI file, you will overwrite this INI message if you have the same paragraph name and keyword in the INI file as the information you want to write. The following is a list of code for the "click" Event for the Button2 component:
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文件!" , "信息" ) ;
}
The correct reading of the INI must meet three prerequisites: The full path to the INI file, the paragraph name, and the keyword name. Otherwise, it will not read correctly. You can set the default value after reading is unsuccessful, in the following program, in order to visually set is "unable to read the corresponding value!" "String, the Read INI file is implemented through the Button3 component's Click event, and the following is its corresponding code list:
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( ) ;
}
The above describes C # to INI file operations