this.controls.addrange (new system.windows.forms.control] {
this.button3,
This.TextBox4,
this.TextBox3,
THIS.TEXTBOX2,
this.button2,
this.TextBox1,
this.button1,
THIS.Label3,
THIS.LABEL2,
THIS.LABEL1});
THIS.MAXIMIZEBOX = FALSE;
THIS.NAME = "Form1";
This.Text = "C # Operate INI File - Write";
This.ResumeLayout (false);
}
[Stathread]
Static void main ()
{
Application.run (New Form1 ());
}
Private void Button1_Click (Object Sender, System.Eventargs E)
{
OpenFileDialog1.showdialog ();
TextBox1.text = OpenFileDialog1.FileName;
}
// Write into INI file
Private void button2_click (Object Sender, System.Eventargs E)
{
String filename = textbox1.text;
String sext.com2.text;
String key = textBox3.text;
String KeyValue = TextBox4.Text;
WritePrivateProfileString (Section, Key, KeyValue, FileName);
Messagebox.show ("Successful Writing Ini File!", "Information");
}
/ / Read the value of keywords in the specific paragraph of the specified INI file
Private void button3_click (Object Sender, System.Eventargs E)
{
StringBuilder Temp = New StringBuilder (255);
String filename = textbox1.text;
String sext.com2.text;
String key = textBox3.text;
INT i = getPrivateProfileString (Section, Key,
"Can't read the corresponding value!", EMP, 255, FileName;
/ / Display the value of the read
TextBox4.text = TEMP.TOSTRING ();
}
}
}
to sum up
Through these introductions above, you can see the process of c # operation INI files, in fact, is the process of C # calling the Win32 API function. Master how to declare the API function of Win32 in C #, then operate INI is very simple.