如何从IniFile加载Combobox.SelectedItem?

时间:2019-03-24 02:25:01

标签: c# ini

我现在正在开发程序,我想在关闭程序时将一些值保存到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()); }

现在我想在启动程序时再次加载然后重新加载吗?

1 个答案:

答案 0 :(得分:0)

检查2:45左右的视频。他展示了如何使用该类的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);

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

    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}");