private void LoadHotkey(out HotKey hk, string name) { hk = HotkeyManager.GetHotKey(name); string defv = hk.ToString(); hk.Apply(INI.GetValue(SECTION_HOTKEY, name, defv)); if (hk.Keys.Length < 2) { hk.Apply(defv); } }
private void SetSetting(Setting setting) { this.Setting = setting; if (pCache.Count == 0) { foreach (var pi in typeof(Setting).GetProperties()) { if (pi.Name.StartsWith("Hk")) { string dKey = pi.Name.Substring(2).ToLower(); pCache.Add(dKey, pi); } } } foreach (Control c in this.Controls) { if (c.GetType() == typeof(ComboBox)) { ComboBox cb = (ComboBox)c; string[] data = null; string dKey = null; bool isBase = false; if (c.Name.StartsWith("cbBase")) { data = BaseKeyNames; dKey = c.Name.Substring(7).ToLower(); isBase = true; } else if (c.Name.StartsWith("cbSub")) { data = SubKeyNames; dKey = c.Name.Substring(6).ToLower(); } else { continue; } HotKey hk = HotkeyManager.GetHotKey(dKey); if (!cache.ContainsKey(dKey)) { cache.Add(dKey, new List <ComboBox>()); } if (cb.Items.Count == 0) { cache[dKey].Add(cb); foreach (var key in data) { cb.Items.Add(key); } cb.SelectedIndexChanged += (s, e) => { if (isBase) { hk.Keys[0] = BaseKeys[cb.SelectedIndex]; } else { hk.Keys[1] = SubKeys[cb.SelectedIndex]; } pCache[dKey].SetValue(setting, hk, null); }; cb.Enabled = hk.Enabled; } cb.SelectedIndex = Array.IndexOf((isBase ? BaseKeys : SubKeys), hk.Keys[isBase ? 0 : 1]); } else if (c.GetType() == typeof(CheckBox)) { CheckBox chk = (CheckBox)c; string dKey = chk.Name.Substring(3).ToLower(); HotKey hk = HotkeyManager.GetHotKey(dKey); chk.CheckedChanged += (s, e) => { foreach (ComboBox b in cache[dKey]) { b.Enabled = chk.Checked; } hk.Enabled = chk.Checked; pCache[dKey].SetValue(setting, hk, null); }; chk.Checked = hk.Enabled; } } }