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