-1

Im working on a Program right now whe i want to save some Values to a Ini File when Closinng and Load then UP again when you open the Program.

The Saving works good and looks like this

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

Now i want to load then up again when i start the Program how do i do that ?

Godly
  • 19
  • 5
  • Well, since your `INIFile` class has a `Write()` method, it probably also has a `Read()` method. Read the values back, then it could be, for example: `SalvageComboBox.SelectedIndex = SalvageComboBox.FindString(ini.Read("SalvageKeySave", "Value"));`. – Jimi Mar 24 '19 at 02:32
  • Welcome. Your question is kinda borderline _too broad_. [ask]. Good luck! –  Mar 24 '19 at 02:34
  • Are you using the class found in [this answer](https://stackoverflow.com/a/14906422/7444103)?. Anyway, I think you could dump the `ini` format and serialize/deserialize a JSON, using a class structure. Much more flexible. Or use the Project settings. – Jimi Mar 24 '19 at 02:39
  • I was using `ini` for all my other Stuff before im open for new things tho. How does JSON work ? never heard about it. – Godly Mar 24 '19 at 02:45
  • and yes im using the Class in the Answer you posted. – Godly Mar 24 '19 at 02:50

1 Answers1

0

Check the video around 2:45. He shows how to use the Read() stuff, of that class.

Believe, you're after:

//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);

If you let the users select a "ctrl - shift - alt key", as part of the shortcut, you'll need to split the incoming value. But, from the code above, it looks like you didn't. Here's the code, in case you change your mind.

    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}");
tobeypeters
  • 464
  • 3
  • 11