C#寫(xiě)入INI文件、讀取INI文件內(nèi)容
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
C#寫(xiě)入INI文件、讀取INI文件內(nèi)容,具體實(shí)現(xiàn)的功能:選擇INI文件、寫(xiě)入INI文件、讀取ini文件,并讀寫(xiě)注冊(cè)表相關(guān)操作,在讀取INI時(shí),讀取指定INI文件的特定段落中的關(guān)鍵字的數(shù)值,請(qǐng)先輸入section和key的值再點(diǎn)擊,可以讀取出INI文件節(jié)點(diǎn)中各個(gè)值的詳細(xì)信息。
private void button1_Click ( object sender , System.EventArgs e ) { try { openFileDialog1.ShowDialog ( ) ; textBox1.Text = openFileDialog1.FileName ; } catch(Exception ex) { MessageBox.Show(ex.Message); } } //寫(xiě)入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 ; try { WritePrivateProfileString ( section , key , keyValue , FileName ) ; MessageBox.Show ( "成功寫(xiě)入INI文件!" , "信息" ) ; } catch(Exception ex) { MessageBox.Show(ex.Message); } } //讀取指定INI文件的特定段落中的關(guān)鍵字的數(shù)值 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 , "無(wú)法讀取對(duì)應(yīng)數(shù)值!" , temp , 255 , FileName ) ; //顯示讀取的數(shù)值 textBox4.Text = temp.ToString ( ) ; } 附件:xmlini.rar 該文章在 2021/2/4 18:36:39 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |