It is easy to use short cuts on a button by appending "&" before the text property of the button.For Example: btnLogin.text=&Loginand that way we can use short cut Alt+ L for the button named btnLogin. But same is not the case with the toolbar button. We need to write a event handler in KeyDown event of the form. Make sure the KeyPreview property of the Form is set to True.Go to forms event tab double click on the keydown event you will be provided with blank function like below.private void form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e){}KeyEventArgs provides event data thus we can capture the key presses. Here is an exmaple how we captureprivate void form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e){if(e.Alt && e.KeyCode == Keys.G){do_job1();}else if(e.Alt && e.KeyCode == Keys.P){do_job2();}else if(e.Alt && e.KeyCode == Keys.L){do_job3();}}In the above example we capture alt(using e.Alt) and whatever key the user enters(using e.KeyCode). And we compare it with the Keys. Keys.letter(what ever letter you have set for the text property of the button) for example In btnLogin.text=&Game we check for Keys.G.Hope that helps.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: