2

I'm a beginner in c# /.NET and this is my first question. I didn't find similar questions.

I have a simple window game where keyboard is useless (similar to Minesweeper). I want to add a "P" shortcut in MenuStrip to "Pause" option.

I tried this in Form1.Designer.cs:

this.pauseToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.P;

but i get a error called System.ComponentModel.InvalidEnumArgumentException. ("Argument value "value" (80) is not the correct to Enum type "Keys". Parameter name: value")

I tried too change it in Solution Explorer -> Properties -> Different -> ShortcutKeys but VisualStudio blocks it and return value to None.

On the other hand i type this line:

this.newgameToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F2;

and it works perfect.

Is there any way to do this? btw sorry for my english if I wrote something wrong.

pear95
  • 66
  • 1
  • 6
  • 1
    The property [stops you](https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/ToolStripMenuItem.cs,480) from using regular typing keys as a shortcut. That is perhaps not so relevant for Minesweeper, but you'd be in for a rude surprise when you add a hi-scores popup that lets the user type in their name. Do it [like this](https://stackoverflow.com/a/400325/17034) instead. – Hans Passant Feb 28 '20 at 15:39
  • 1
    Thanks, this solution is fine, but Is it possible to put a "P" shortcut (visible) on the MenuStrip? The only way that i found to do this is changing text in pauseToolStripMenuItem to "Pause__________P" but this explanation is dirty. – pear95 Feb 28 '20 at 19:13
  • If you mean highlighting the shortcut on the menu you could use Unicode like this in the menu name: P̲ause – PeterJ Feb 29 '20 at 13:24

0 Answers0