private void ReadKeySettingFromXml() { var reader = XmlReader.Create(keyConfigFileName, new XmlReaderSettings()); while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.LocalName) { case "KeyConfigs": keyConfigs.Clear(); break; case "KeyConfig": var keyConfig = new KeyConfig { Name = reader.GetAttribute("Name") }; AddKeyConfig(keyConfig); ReadKeySetting(reader.ReadSubtree(), keyConfig); break; } } } reader.Close(); if (keyConfigs.Count == 0) { AddKeyConfig(new KeyConfig()); } }
private void ApplyConfigToDataGrid(KeyConfig config) { for (int i = 0; i < ButtonUtility.Array.Length; i++) { this.dataGridView1.Rows[i].Cells[0].Value = config.GetKeyMap(ButtonUtility.Array[i]).ToString(); this.dataGridView1.Rows[i].Cells[1].Value = config.GetButtonMap(ButtonUtility.Array[i]).ToString(); } }
private void AddKeyConfig(KeyConfig keyConfig) { keyConfigs.Add(keyConfig); var tsmi = new ToolStripMenuItem(keyConfig.Name); tsmi.Text = tsmi.ToolTipText = keyConfig.Name; tsmi.Tag = keyConfig; tsmi.Click += tsmi_Click1; this.設定ToolStripMenuItem.DropDownItems.Add(tsmi); }
private void WriteSetting(XmlWriter writer, KeyConfig keyConfig) { foreach (ButtonType buttonType in ButtonUtility.Array) { writer.WriteStartElement("Config"); writer.WriteAttributeString("Type", buttonType.ToString()); writer.WriteAttributeString("Key", keyConfig.GetKeyMap(buttonType).ToString()); writer.WriteAttributeString("Button", keyConfig.GetButtonMap(buttonType).ToString()); writer.WriteEndElement(); } }
public KeyConfig Clone() { var ret = new KeyConfig(); foreach (ButtonType type in ButtonUtility.Array) { ret.SetKeyMap(type, GetKeyMap(type)); ret.SetButtonMap(type, GetButtonMap(type)); } return(ret); }
private void ReadKeySettingFromIni() { var keyConfig = new KeyConfig(); var sr = new StreamReader(keyConfigFileName); var s = sr.ReadToEnd().Replace("\r\n", "\n").Replace("\r", "\n"); sr.Close(); var sp = s.Split('\n'); for (int i = 0; i < Math.Min(sp.Length, ButtonUtility.Array.Length); i++) { var secondsp = sp[i].Split(':'); if (secondsp.Length >= 2) { keyConfig.SetKeyMap(ButtonUtility.Array[i], int.Parse(secondsp[0])); keyConfig.SetButtonMap(ButtonUtility.Array[i], int.Parse(secondsp[1])); } } AddKeyConfig(keyConfig); }
private void ReadKeySetting(XmlReader reader, KeyConfig keyConfig) { while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.LocalName) { case "Config": int key = int.Parse(reader.GetAttribute("Key")), button = int.Parse(reader.GetAttribute("Button")), index = FindIndex(reader.GetAttribute("Type")); if (index >= 0) { keyConfig.SetKeyMap(ButtonUtility.Array[index], key); keyConfig.SetButtonMap(ButtonUtility.Array[index], button); } break; } } } reader.Close(); }