public void InitShortcuts() { shortcuts = new ShortcutsSaver(); foreach (var m in MenuEnumerable(this.menu.Items)) shortcuts.AddMenu(m.Text, m.ShortcutKeys); foreach (var m in MenuEnumerable(cubeView.TopContextMenuStrip.Items)) shortcuts.AddMenu(m.Text, m.ShortcutKeys); shortcuts.Add("下一步动画", "cubeView", "Ani2Next", Keys.N); shortcuts.Add("退一步动画", "cubeView", "Ani2Back", Keys.B); shortcuts.Add("播放动画", "cubeView", "AniPlay", Keys.Space); shortcuts.Add("退到开头动画", "cubeView", "Ani2Begin"); shortcuts.Add("连续动画时暂停", "cubeView", "AniPause"); shortcuts.Add("设置到下一步", "cubeView", "Set2Next"); shortcuts.Add("设置到上一步", "cubeView", "Set2Back"); shortcuts.Add("设置到开头", "cubeView", "Set2Begin"); shortcuts.Add("设置到结尾", "cubeView", "Set2End"); shortcuts.Add("左旋魔方", "cubeView", "RotateLeftY", Keys.Left); shortcuts.Add("右旋魔方", "cubeView", "RotateRightY", Keys.Right); shortcuts.Add("放大魔方", "cubeView", "ZoomUp3", Keys.Up); shortcuts.Add("缩小魔方", "cubeView", "ZoomDown3", Keys.Down); }
//public OptionForm() //{ // InitializeComponent(); //} public OptionForm(MainForm parent, string sel) { InitializeComponent(); cubeView = parent.cubeView; shortcuts = parent.shortcuts; treeView.SelectedNode = GetNode(treeView.Nodes, sel); }
private void LoadShortcuts() { // 初始化快捷键设置,如果没有则使用默认值 if (string.IsNullOrEmpty(Settings.Default.Shortcuts)) { InitShortcuts(); return; } // 如果有设置则读取,并设置菜单快捷键 byte[] bytes = Convert.FromBase64String(Settings.Default.Shortcuts); MemoryStream ms = new MemoryStream(bytes); BinaryFormatter bf = new BinaryFormatter(); shortcuts = (ShortcutsSaver)bf.Deserialize(ms); // 将所有菜单快捷键设置进菜单 foreach (Shortcut stc in shortcuts.Menus()) { ToolStripMenuItem menu = FindMenu(stc.Text); if (menu == null) continue; if (stc.Key != Keys.None) { Keys key = stc.Key; if (stc.Alt) key |= Keys.Alt; if (stc.Ctrl) key |= Keys.Control; if (stc.Shift) key |= Keys.Shift; menu.ShortcutKeys = key; } } }