//from http://stackoverflow.com/a/1718483 private void gvProfiles_MouseClick(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Right) { int currentMouseOverRow = gvProfiles.HitTest(e.X, e.Y).RowIndex; if (currentMouseOverRow >= 0) { profileBindingSource.Position = currentMouseOverRow; ContextMenu m = new ContextMenu(); m.MenuItems.Add(new MenuItem("Add Hotkey")); m.MenuItems[0].Click += (s, eArgs) => { GetHotkey getHotkey = new GetHotkey(); Profile selection = (Profile)profileBindingSource[currentMouseOverRow]; if (selection.Hotkey != null) { getHotkey.Key = selection.Hotkey.KeyCode; getHotkey.Shift = selection.Hotkey.Shift; getHotkey.Alt = selection.Hotkey.Alt; getHotkey.Ctrl = selection.Hotkey.Control; } if (getHotkey.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //Get the current position of this in the settings. We will have to save it there int pos = Properties.Settings.Default.Profiles.IndexOf(SerialiseProfile(selection)); if (selection.Hotkey != null && selection.Hotkey.Registered) { selection.Hotkey.Unregister(); } selection.Hotkey = new Hotkey(getHotkey.Key, getHotkey.Shift, getHotkey.Ctrl, getHotkey.Alt, false); //Save the profile in settings Properties.Settings.Default.Profiles[pos] = SerialiseProfile(selection); Properties.Settings.Default.Save(); RegisterHotkey(selection); } }; m.Show(gvProfiles, new Point(e.X, e.Y)); } } }
//from http://stackoverflow.com/a/1718483 private void gvProfiles_MouseClick(object sender, MouseEventArgs e) { if(e.Button == System.Windows.Forms.MouseButtons.Right) { int currentMouseOverRow = gvProfiles.HitTest(e.X, e.Y).RowIndex; if (currentMouseOverRow >= 0) { profileBindingSource.Position = currentMouseOverRow; ContextMenu m = new ContextMenu(); m.MenuItems.Add(new MenuItem("Add Hotkey")); m.MenuItems[0].Click += (s, eArgs) => { GetHotkey getHotkey = new GetHotkey(); Profile selection = (Profile)profileBindingSource[currentMouseOverRow]; if(selection.Hotkey != null) { getHotkey.Key = selection.Hotkey.KeyCode; getHotkey.Shift = selection.Hotkey.Shift; getHotkey.Alt = selection.Hotkey.Alt; getHotkey.Ctrl = selection.Hotkey.Control; } if (getHotkey.ShowDialog() == System.Windows.Forms.DialogResult.OK) { //Get the current position of this in the settings. We will have to save it there int pos = Properties.Settings.Default.Profiles.IndexOf(SerialiseProfile(selection)); if (selection.Hotkey != null && selection.Hotkey.Registered) { selection.Hotkey.Unregister(); } selection.Hotkey = new Hotkey(getHotkey.Key, getHotkey.Shift, getHotkey.Ctrl, getHotkey.Alt, false); //Save the profile in settings Properties.Settings.Default.Profiles[pos] = SerialiseProfile(selection); Properties.Settings.Default.Save(); RegisterHotkey(selection); } }; m.Show(gvProfiles, new Point(e.X, e.Y)); } } }