2015-06-14 57 views
-2

我正在嘗試使用它來編輯ini,但我似乎無法獲取將ini文件的該部分添加到RichTextbox中的代碼。在Visual C中編輯Ini文件#

 if (myIni.GetSection(String.Format("[{0}]", comboBox1.SelectedItem.ToString().ToUpper())) != null); 
     { 
      mySection = new IniFile.IniSection(myIni, String.Format("{0}", comboBox1.SelectedItem.ToString().ToUpper())); 
      foreach (IniFile.IniSection.IniKey key in mySection.Keys) 
      { 
       richTextBox1.AppendText(String.Format("{0}={1}{2}", key.Name, key.Value, Environment.NewLine)); 
      } 
     } 

我不知道我的代碼有什麼問題。

+0

你有沒有調試? 'mySection'什麼都沒有? 'mySection.Keys'包含數據嗎? –

+0

@RonBeyer我該如何檢查? – Darakath

+0

通過使用調試器?這是c#編程基礎...... – walther

回答

0

您可以使用從Windows舊的現有INI電話:

[System.Runtime.InteropServices.DllImport("kernel32")] 
static extern int GetPrivateProfileString(string section, 
     string key, string def, StringBuilder retVal, 
     int size, string filePath); 
[System.Runtime.InteropServices.DllImport("kernel32")] 
static extern long WritePrivateProfileString(string section, 
     string key, string val, string filePath); 

...

StringBuilder temp = new StringBuilder(255); 
GetPrivateProfileString("section", "key", "default", temp, 255, inifilename); 
String value = temp.ToString(); 


WritePrivateProfileString("section", "key", value, inifilename);