SIGN UP MEMBER LOGIN:    
ARTICLE

Short Cuts for Toolbar Buttons

Posted by kiran_kuchiba Articles | Windows Forms C# July 26, 2004
This tutorial tells the story about "How to create short cuts for toolbar buttons?".
Reader Level:

It is easy to use short cuts on a button by appending "&" before the text property of the button.

For Example:

btnLogin.text=&Login

and 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 capture

private 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.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor