C# - shortcut Shift + some char not compiling
I work in Visual Studio 2008 (framework 3.5) and I am trying to add shortcut (for example Shift +
D) to menuStrip (exactly to toolStrip in menuStrip) but I can´t. I get error:"The value of arg开发者_开发知识库ument 'value' (65604) is invalid for Enum type
Keys
.
Parameter name: value". It shows just with Shift. With Ctrl, Alt it´s ok. Even when I tried Ctrl + Shift + D then it worked but not with just Shift and letter.
You can't use shift and a letter, digit or other character as a shortcut key, since the shift key works as a modifier -- it'd be like typing A when you really meant shift + A.
EDIT: I didn't find anything in the docs that stated it, but in this question it's stated that you can only use ctrl or alt in combination with a letter or digit. Though, you can of course use shift with ctrl or alt in any combination with another key!
The shift key is a modifier key on a keyboard, used to type capital letters and other alternate "upper" characters. It can only be used for shortcuts in conjunction with keys which do not have any alternate usages.
You Could override it. It would let you use Shift with other keys, like Ctrl + Shift + Tab or Ctrl + tab n such. I ended up with the same problem and this is how I solved my problem :
public class ExtendedTabControl: TabControl
{
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.Tab))
{
// Write custom logic here
return true;
}
if (keyData == (Keys.Control | Keys.Shift | Keys.Tab))
{
// Write custom logic here
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
I hope it helps
精彩评论