我如何从 IniFile 加载 Combobox.SelectedItem?

How do i load Combobox.SelectedItem from a IniFile?

我现在正在开发一个程序,我想在关闭时将一些值保存到 Ini 文件中,然后在打开程序时再次加载。

保存效果很好,看起来像这样

       private void Form2_FormClosing(object sender, FormClosingEventArgs e)
    {
        INIFile ini = new INIFile("C:\GodToolSettings.ini");
        ini.Write("SalvageKeySave", "Value", SalvageComboBox.SelectedItem.ToString());
        ini.Write("InvDropSave", "Value", invdropcombo.SelectedItem.ToString());
        ini.Write("GambleSave", "Value", gamblecombo.SelectedItem.ToString());
        ini.Write("LClickspamSave", "Value", lclickspamcombo.SelectedItem.ToString());
        ini.Write("GemUpsSave", "Value", GemUpsCombo.SelectedItem.ToString());
        ini.Write("OpenGRSave", "Value", OpenGRcombo.SelectedItem.ToString());
        ini.Write("PauseSave", "Value", PauseCombo.SelectedItem.ToString()); }

现在我想在启动程序时再次加载,我该怎么做?

查看 2:45 周围的视频。他展示了如何使用 class.

中的 Read() 内容

相信,你在追求:

//I assume, you set the ComboBox DropDownStyle to DropDownList, to keep people from being able to type in bad key info?
comboBox1.SelectedIndex = comboBox1.FindStringExact(stringtofind);

如果让用户 select 一个 "ctrl - shift - alt key" 作为快捷方式的一部分,则需要拆分传入值。但是,从上面的代码来看,您似乎没有。这是代码,以防您改变主意。

    Keys hookKey = (Keys)new KeysConverter().ConvertFrom(value); //If value is a string

    checkBox1.Checked = ((hookKey & Keys.Control) == Keys.Control);
    checkBox2.Checked = ((hookKey & Keys.Alt) == Keys.Alt);
    checkBox3.Checked = ((hookKey & Keys.Shift) == Keys.Shift);

    hookKey = (((hookKey & Keys.Control) == Keys.Control) ? (hookKey &= ~Keys.Control) : hookKey);
    hookKey = (((hookKey & Keys.Shift) == Keys.Shift) ? (hookKey &= ~Keys.Shift) : hookKey);
    hookKey = (((hookKey & Keys.Alt) == Keys.Alt) ? (hookKey &= ~Keys.Alt) : hookKey);

    MessageBox.Show($"hookKey should only hold the key you need to put in the combobox : {hookKey}");