/// <summary> /// フォームのロードイベント /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormKeyEditor_Load(object sender, EventArgs e) { var layout = LayoutLoader.Load(@".\EditorLayout.xml"); if (!CheckLayoutParam(layout)) { Close(); return; } var settings = ShortcutKeyManager.LoadSettings(@".\shortcutkeys.xml"); if (settings == null) { settings = new Dictionary <string, ShortcutKeyManager.KeySet>(); } foreach (var layoutTab in layout.Tabs) { var tabPage = new TabPage(); tabPage.Text = layoutTab.Label; tabPage.AutoScroll = true; tabPage.BackColor = layout.Skin.PanelColor.Background; var flowPanel = new FlowLayoutPanel(); flowPanel.Dock = DockStyle.Fill; flowPanel.AutoScroll = true; flowPanel.BackColor = layout.Skin.PanelColor.Background; int labelMaxWidth = 0; foreach (var layoutKeySet in layoutTab.KeySets) { var keySetName = layoutTab.Name + "_" + layoutKeySet.Name; var keyset = new KeySetControl(); keyset.KeySetName = keySetName; keyset.SetLabelText(layoutKeySet.Label); keyset.SetKeyText(settings.ContainsKey(keySetName) ? settings[keySetName].KeyText : layoutKeySet.KeyText); keyset.LabelColor = layout.Skin.KeyColor.Label; keyset.TextColor = layout.Skin.KeyColor.Text; keyset.TextboxColor = layout.Skin.KeyColor.Textbox; keyset.BackColor = layout.Skin.KeyColor.Background; keyset.Tag = layoutKeySet; flowPanel.Controls.Add(keyset); labelMaxWidth = Math.Max(keyset.LabelWidth, labelMaxWidth); } tabPage.Controls.Add(flowPanel); tabControlMain.TabPages.Add(tabPage); // 表示幅の調整 foreach (var control in flowPanel.Controls) { if (control is KeySetControl) { var keyset = control as KeySetControl; keyset.Width = keyset.Width + labelMaxWidth; } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_save_settings_Click(object sender, EventArgs e) { var keysets = new List <ShortcutKeyManager.KeySet>(); foreach (TabPage tabPage in tabControlMain.TabPages) { var flowPanel = tabPage.Controls[0] as FlowLayoutPanel; foreach (var control in flowPanel.Controls) { if (control is KeySetControl) { var keysetControl = control as KeySetControl; // ここでショートカットキーをテキストとしてだけではなくKeys の値も数値として書き込むと扱いやすいが // 設定ファイルを直接開いて、ショートカットキーのテキストだけをユーザーが書き換える可能性がある // (書き換える使い方を許容したい)ので、キーはテキストとして書き込むだけにしておく var keyset = new ShortcutKeyManager.KeySet(); keyset.Name = keysetControl.KeySetName; keyset.KeyText = keysetControl.KeyText; keysets.Add(keyset); } } } var hashset = new HashSet <string>(); foreach (var keyset in keysets) { if (keyset.KeyText != "None" && !hashset.Add(keyset.KeyText)) { MessageBox.Show( keyset.KeyText + " が重複して登録されています。", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (ShortcutKeyManager.WriteSettings(@"./shortcutkeys.xml", keysets)) { Close(); } }
public void SetupShortcutKeys() { ShortcutKeyManager.Clear(); ShortcutKeyManager.Register(EditingActions.Copy, Keys.Control | Keys.C); ShortcutKeyManager.Register(SelectionActions.MoveToNextCell, Keys.Tab); ShortcutKeyManager.Register(SelectionActions.MoveToPreviousCell, Keys.Tab | Keys.Shift); ShortcutKeyManager.Register(SelectionActions.MoveUp, Keys.Up); ShortcutKeyManager.Register(SelectionActions.MoveDown, Keys.Down); ShortcutKeyManager.Register(SelectionActions.MoveLeft, Keys.Left); ShortcutKeyManager.Register(SelectionActions.MoveRight, Keys.Right); ShortcutKeyManager.Register(SelectionActions.MoveToFirstCellInRow, Keys.Home); ShortcutKeyManager.Register(SelectionActions.MoveToLastCellInRow, Keys.End); ShortcutKeyManager.Register(SelectionActions.MoveToFirstRow, Keys.Up | Keys.Control); ShortcutKeyManager.Register(SelectionActions.MoveToLastRow, Keys.Down | Keys.Control); ShortcutKeyManager.Register(SelectionActions.MoveToFirstCellInRow, Keys.Left | Keys.Control); ShortcutKeyManager.Register(SelectionActions.MoveToLastCellInRow, Keys.Right | Keys.Control); ShortcutKeyManager.Register(SelectionActions.MoveToFirstCell, Keys.Home | Keys.Control); ShortcutKeyManager.Register(SelectionActions.MoveToLastCell, Keys.End | Keys.Control); ShortcutKeyManager.Register(SelectionActions.ShiftUp, Keys.Up | Keys.Shift); ShortcutKeyManager.Register(SelectionActions.ShiftDown, Keys.Down | Keys.Shift); ShortcutKeyManager.Register(SelectionActions.ShiftLeft, Keys.Left | Keys.Shift); ShortcutKeyManager.Register(SelectionActions.ShiftRight, Keys.Right | Keys.Shift); ShortcutKeyManager.Register(SelectionActions.ShiftToFirstCellInRow, Keys.Home | Keys.Shift); ShortcutKeyManager.Register(SelectionActions.ShiftToLastCellInRow, Keys.End | Keys.Shift); ShortcutKeyManager.Register(SelectionActions.ShiftToFirstRow, Keys.Up | Keys.Shift | Keys.Control); ShortcutKeyManager.Register(SelectionActions.ShiftToLastRow, Keys.Down | Keys.Shift | Keys.Control); ShortcutKeyManager.Register(SelectionActions.ShiftToFirstCellInRow, Keys.Left | Keys.Shift | Keys.Control); ShortcutKeyManager.Register(SelectionActions.ShiftToLastCellInRow, Keys.Right | Keys.Shift | Keys.Control); ShortcutKeyManager.Register(SelectionActions.ShiftToFirstCell, Keys.Home | Keys.Shift | Keys.Control); ShortcutKeyManager.Register(SelectionActions.ShiftToLastCell, Keys.End | Keys.Shift | Keys.Control); ShortcutKeyManager.Register(new MultiRow.Action.CheckSelectedCells(), Keys.Space); ShortcutKeyManager.DefaultModeList.Add(new ShortcutKey(SelectionActions.MoveToNextCell, Keys.Return)); ShortcutKeyManager.Register(EditingActions.ShowDropDown, Keys.Alt | Keys.Down); }