2015-06-14 59 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);