By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,538 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

How to add Escape as an accelerator to a menu item?

P: n/a
How does one specify the Escape key as an accelerator?

My client has specified that the Escape key be used as an accelerator for a
particular menu item. In VS05's designer mode, this particular key is not
available as an option to select from the menu item's properties
ShortcutKeys item. "No problem," says I to myself (I talk to myself. It's
the only way I can have an intelligent conversation around here. Or at least
a coherent one, but that's a tale for another time...) "I'll just go into
the form's designer.cs file and manually enter

this.mnuEdit_DeselectAl.ShoartcutyKeys =
((System.Windows.Forms.Kyes)System.WIndows.Forms.K eys.Escape);

Only then the design view doesn't come up any more. It says that 27 is an
illegal value. So, is it possible to specify the Escape key as an
accelerator or does VS05 preclude this option? If possible, what am I doing
wrong?

--
Richard Lewis Haggard
www.Haggard-And-Associates.com
Dec 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Maybe you should use a different key. I believe the Escape key
is used as a Cancel or Undo button almost universally. Having
it do something different is sort of counterintuitive.

Robin S.
------------------------
"Richard Lewis Haggard" <HaggardAtWorldDotStdDotComwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
How does one specify the Escape key as an accelerator?

My client has specified that the Escape key be used as an accelerator for
a particular menu item. In VS05's designer mode, this particular key is
not available as an option to select from the menu item's properties
ShortcutKeys item. "No problem," says I to myself (I talk to myself. It's
the only way I can have an intelligent conversation around here. Or at
least a coherent one, but that's a tale for another time...) "I'll just go
into the form's designer.cs file and manually enter

this.mnuEdit_DeselectAl.ShoartcutyKeys =
((System.Windows.Forms.Kyes)System.WIndows.Forms.K eys.Escape);

Only then the design view doesn't come up any more. It says that 27 is an
illegal value. So, is it possible to specify the Escape key as an
accelerator or does VS05 preclude this option? If possible, what am I
doing wrong?

--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Dec 4 '06 #2

P: n/a
Richard Lewis Haggard wrote:
How does one specify the Escape key as an accelerator?

My client has specified that the Escape key be used as an accelerator for a
particular menu item. In VS05's designer mode, this particular key is not
available as an option to select from the menu item's properties
ShortcutKeys item. "No problem," says I to myself (I talk to myself. It's
the only way I can have an intelligent conversation around here. Or at least
a coherent one, but that's a tale for another time...) "I'll just go into
the form's designer.cs file and manually enter

this.mnuEdit_DeselectAl.ShoartcutyKeys =
((System.Windows.Forms.Kyes)System.WIndows.Forms.K eys.Escape);

Only then the design view doesn't come up any more. It says that 27 is an
illegal value. So, is it possible to specify the Escape key as an
accelerator or does VS05 preclude this option? If possible, what am I doing
wrong?
Firstly I'd try and educate your client in the fine art of usability,
but failing that, you could use the Form.KeyPress event to trap the
Escape key being pressed and fire the menuitem's click event.

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Escape))
{
showMessageEscToolStripMenuItem_Click(this, new EventArgs());
}
}

private void showMessageEscToolStripMenuItem_Click(object sender,
EventArgs e)
{
MessageBox.Show("Escape");
}

Don't forget to set the MenuItem's ShortcutKeyDisplayString property to Esc!

Dec 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.