将 TextBox 值保存到 Ini 文件

Save TextBox value to Ini File

我已经从这里的另一位成员那里得到了一些很大的帮助。然而,我又卡住了。 我有一个 cfg 文件,它基本上与 Ini 文件完全相同。我可以将 Sections 加载到 ListBox1 中,当我 select a Section 时它在 ListBox2 中显示 Key,当我 select a Key 时它在 TextBox1 中显示该键的值。多亏了这里的一位成员,这一切都完美无缺。 现在,我遇到的问题是,如果我想更改 TextBox1 中显示的值并将其保存到 cfg 文件中。 我已经尝试了 SaveFileDialog 的正常方法。但我不想有保存新文件的选项。我只想更改现有文件中的值而不显示对话框。希望这是有道理的。

代码如下:

这会加载 ListBox1:

Dim ini As New INI(Environ("USERPROFILE") & "path-to-cfg")
ListBox1.Items.AddRange(ini.GetSectionNames()) 'For all sections

这从列表框 1 中的 selected 项加载列表框 2:

Dim ini As New INI(Environ("USERPROFILE") & "path-to-cfg")
Dim section As String = ListBox1.SelectedItem
ListBox2.Items.Clear()
For Each item In ini.GetEntryNames(section)
   ListBox2.Items.Add(item)
Next

这在 TextBox1 中显示了来自 ListBox2 中 selected 项的值:

Dim ini As New INI(Environ("USERPROFILE") & "path-to-cfg")
Dim value As String = ListBox2.SelectedItem

TextBox1.Text = ini.GetEntryValue(ListBox1.SelectedItem, ListBox2.SelectedItem)

非常感谢任何帮助。

干杯, 旦

已解决。

我按照以下 link 中的示例进行操作,效果很好。 无论如何感谢您的帮助。非常感谢。

对于那些感兴趣的人:Click Here

谢谢,