this.button2.tabindex = 3 ;
this.button2.text = "写入ini文件" ;
this.button2.click += new system.eventhandler ( this.button2_click ) ;
this.textbox2.location = new system.drawing.point ( 160 , 62 ) ;
this.textbox2.name = "textbox2" ;
this.textbox2.size = new system.drawing.size ( 176 , 21 ) ;
this.textbox2.tabindex = 5 ;
this.textbox2.text = "" ;
this.textbox3.location = new system.drawing.point ( 160 , 94 ) ;
this.textbox3.name = "textbox3" ;
this.textbox3.size = new system.drawing.size ( 176 , 21 ) ;
this.textbox3.tabindex = 6 ;
this.textbox3.text = "" ;
this.textbox4.location = new system.drawing.point ( 160 , 128 ) ;
this.textbox4.name = "textbox4" ;
this.textbox4.size = new system.drawing.size ( 176 , 21 ) ;
this.textbox4.tabindex = 7 ;
this.textbox4.text = "" ;
this.label1.location = new system.drawing.point ( 56 , 62 ) ;
this.label1.name = "label1" ;
this.label1.tabindex = 8 ;
this.label1.text = "段落名称:" ;
this.label2.location = new system.drawing.point ( 66 , 96 ) ;
this.label2.name = "label2" ;
this.label2.tabindex = 9 ;
this.label2.text = "关键字:" ;
this.label3.location = new system.drawing.point ( 42 , 130 ) ;
this.label3.name = "label3" ;
this.label3.tabindex = 10 ;
this.label3.text = "关键字数值:" ;
this.button3.flatstyle = system.windows.forms.flatstyle.flat ;
this.button3.location = new system.drawing.point ( 208 , 168 ) ;
this.button3.name = "button3" ;
this.button3.size = new system.drawing.size ( 98 , 30 ) ;
this.button3.tabindex = 11 ;
this.button3.text = "读取ini数值" ;
this.button3.click += new system.eventhandler ( this.button3_click ) ;
this.openfiledialog1.filter = "ini 文件|*.ini" ;
this.autoscalebasesize = new system.drawing.size ( 6 , 14 ) ;
this.clientsize = new system.drawing.size ( 366 , 217 ) ;
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#操作ini文件--写操作" ;
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 ;
}
//写入ini文件
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文件!" , "信息" ) ;
}
//读取指定ini文件的特定段落中的关键字的数值
private void button3_click ( object sender , system.eventargs e )
{
,欢迎访问网页设计爱好者web开发。