【问题标题】:How do i load Combobox.SelectedItem from a IniFile? [closed]如何从 IniFile 加载 Combobox.SelectedItem? [关闭]
【发布时间】:2019-03-24 02:25:00
【问题描述】:

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

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

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

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

【问题讨论】:

  • 好吧,既然你的INIFile 类有一个Write() 方法,它可能也有一个Read() 方法。读回这些值,然后它可能是,例如:SalvageComboBox.SelectedIndex = SalvageComboBox.FindString(ini.Read("SalvageKeySave", "Value"));
  • 欢迎。你的问题有点太宽泛了。 How to Ask。祝你好运!
  • 你在使用this answer中的类吗?无论如何,我认为您可以转储 ini 格式并使用类结构序列化/反序列化 JSON。灵活得多。或使用项目设置。
  • 在我接受新事物之前,我一直在使用ini 处理我的所有其他东西。 JSON 是如何工作的?没听说过。
  • 是的,我正在使用您发布的答案中的类。

标签: c# ini


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-02-19
    • 2014-02-28
    • 2014-04-23
    • 2021-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 2011-07-03
    相关资源
    最近更新 更多