Dear all,

I have no idea to set a hot key for the command button in my VB window
application program. Do any person know how to do it?
Thank you

miyakejess

Re: Is Any person know how to set a hotkey for command button? by Sijin

Sijin
Fri Nov 05 01:07:27 CST 2004

If this is a VB.Net app then you need to set KeyPreivew = true for the
form on which the button resides and then write an event handler for the
keydown event which will then fire the button command if the right key
is pressed..

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

miyakejess wrote:
> Dear all,
>
> I have no idea to set a hot key for the command button in my VB window
> application program. Do any person know how to do it?
> Thank you
>
> miyakejess

Re: Is Any person know how to set a hotkey for command button? by Justin

Justin
Fri Nov 05 02:39:11 CST 2004

If you don't need a context menu in your application you can use one to add
shortcut keys... You can even still have a context menu, but you have to do
some extra work if you don't want the button items showing.

using System;
using System.Windows.Forms;

public class ShortcutButton : Form {
private Button button = new Button();
private ContextMenu ctxMenu = new ContextMenu();
private MenuItem shortcutButton = new MenuItem();

private ShortcutButton() {
this.shortcutButton.Shortcut = Shortcut.CtrlB;
this.shortcutButton.Click += new EventHandler(Button_Click);
this.ctxMenu.MenuItems.Add(shortcutButton);
this.ContextMenu = ctxMenu;
this.button.Click += new EventHandler(Button_Click);

this.Controls.Add(button);
}

protected override void WndProc(ref Message m) {
switch(m.Msg) {
case 0x7b:
break;
default:
base.WndProc(ref m);
break;
}
}

private void Button_Click(object sender, EventArgs e) {
MessageBox.Show(this, "Foo");
}

private static void Main(string[] args) {
Application.Run(new ShortcutButton());
}
}


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Sijin Joseph" <sijinNOSPAMdotnet@hotmail.com> wrote in message
news:uR0AeYwwEHA.2192@TK2MSFTNGP14.phx.gbl...
> If this is a VB.Net app then you need to set KeyPreivew = true for the form on
> which the button resides and then write an event handler for the keydown event
> which will then fire the button command if the right key is pressed..
>
> Sijin Joseph
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph
>
> miyakejess wrote:
>> Dear all, I have no idea to set a hot key for the command button in my VB
>> window application program. Do any person know how to do it?
>> Thank you
>>
>> miyakejess



Re: Is Any person know how to set a hotkey for command button? by Herfried

Herfried
Fri Nov 05 06:42:59 CST 2004

"miyakejess" <miyakejess@discussions.microsoft.com> schrieb:
> I have no idea to set a hot key for the command button in my VB window
> application program. Do any person know how to do it?

If you want to add an Alt+* mnemonic, simply add a "&" in front of the
character that should be the mnemonic key in the 'Text' property, for
example, "&Save".

For shortcut keys, add a MainMenu and add items with shortcuts, then make
the items invisible and add handlers to their 'Click' events. These
handlers will be called if the according shortcuts are pressed.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Re: Is Any person know how to set a hotkey for command button? by miyakejess

miyakejess
Mon Nov 08 01:34:01 CST 2004

Actually, I want to make a shortcut key in Context menu
I have tried something similar to Justin Rogers' suggestion,
but it seems that, the computer dosn't know i want the short cut i press is
refer to my application.
Instead, it runs the short cut key defined in other applications.
so, how can i code to tell the computer to do the action on my application?



Re: Is Any person know how to set a hotkey for command button? by RonBarone

RonBarone
Tue Nov 09 12:04:02 CST 2004

You might be able to capture the key events globally using DirectInput. I
dont recall exaclty how to do this, (did it in VB6 awhile back) but I know it
wasnt very straight forward. I used it for mouse and joystick events.

Hope that helps.


"miyakejess" wrote:

> Actually, I want to make a shortcut key in Context menu
> I have tried something similar to Justin Rogers' suggestion,
> but it seems that, the computer dosn't know i want the short cut i press is
> refer to my application.
> Instead, it runs the short cut key defined in other applications.
> so, how can i code to tell the computer to do the action on my application?
>
>