MenuItem.Shortcut has no Esc key?!
-
Why is that? How else can I assign the Esc shortcut to a menu item? Sammy "A good friend, is like a good book: the inside is better than the cover..."
-
Why is that? How else can I assign the Esc shortcut to a menu item? Sammy "A good friend, is like a good book: the inside is better than the cover..."
profoundwhispers wrote: How else can I assign the Esc shortcut to a menu item? You can P/Invoke
RegisterHotKey
, you might also want to includeUnregisterHotKey
. However why would you want to assign Esc to a menu item, usually when a form is open and someone presses the Esc key it will close the current window. - Nick Parker
My Blog -
Why is that? How else can I assign the Esc shortcut to a menu item? Sammy "A good friend, is like a good book: the inside is better than the cover..."
The old fashion way: set the
MenuItem.Text
to "My Caption\tEsc". Notice that you should inserting a tab character between the caption and the shortcut. Don't use the PropertyGrid to do this, since it will escape the backslash (\) as well. You'll need to handle the escape key yourself, though, by settingForm.KeyPreview
totrue
and overriding theOnKeyDown
method in your derivedForm
class to handleKeys.Escape
.Microsoft MVP, Visual C# My Articles
-
profoundwhispers wrote: How else can I assign the Esc shortcut to a menu item? You can P/Invoke
RegisterHotKey
, you might also want to includeUnregisterHotKey
. However why would you want to assign Esc to a menu item, usually when a form is open and someone presses the Esc key it will close the current window. - Nick Parker
My BlogNick Parker wrote: However why would you want to assign Esc to a menu item Oh, I hate unstandard windows application like this, you can't do anything with them. :doh: Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
-
Nick Parker wrote: However why would you want to assign Esc to a menu item Oh, I hate unstandard windows application like this, you can't do anything with them. :doh: Mazy "A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work! So how can I simply make it work!? Sammy "A good friend, is like a good book: the inside is better than the cover..."
-
Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work! So how can I simply make it work!? Sammy "A good friend, is like a good book: the inside is better than the cover..."
profoundwhispers wrote: Actually, what I'm trying to do is pretty standard, although it's a workaround. See, when I use the AxWebBrowser control, pressing on Esc to stop the page from loading doesn't seem to work, so I was trying to make it work! Well, I am not sure what a menu item has to do with what you just said, per your original post. I still think you are going to want to use the
RegisterHotKey
and probably override the WndProc. Something like the following:protected override void WndProc(ref Message m)
{
const int WM_HOTKEY = 0x0312;
switch(m.Msg)
{
case WM_HOTKEY:
ProcessHotKey();
}
base.WndProc(ref m);
}private void ProcessHotKey()
{
// Handle AxWebBrowser here.
}- Nick Parker
My Blog