How To Create Hot Key in Windows Application With Csharp

This is my 4th Tutorial about the basic Windows Programming. Hot key are such key which we embed is in our application for ease of user. For example when we write a URL in browser we write Google and then press Ctrl+Enter then URL look like this http://www.google.com it’s a basic example. we use Alt+F4 to close any kind of window. If you never done this before then your may be thinking that it is very difficult but dear you will surprise to know that its so much easy to create a Hot Key in Windows Application with Csharp.

sabre-oled



Requirement for the use of timer control is following.

  • Operating System : Windows XP, Windows 7 , Vista
  • Platform :  .Net 2.0 or greater
  • IDE : Visual Studio
  • Language : Csharp
Now Follow the following steps :
  1. Create New Project on Visual Studio
  2. Select language C#
  3. Now Select the Windows Application

Now I am going to use it in the Form’s event.

1Now Select KeyDown or KeyUp Event and Press Enter key that will open code of that event. Then write the following line of code:

private void Form1_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.F)
           {
              MessageBox.Show("KEY PRESSED");

     }
       }

In above code I Write the code for the F or f key press. There are numbers of keys available.

2

Then go the load event of Form and write following code:

private void Form1_Load(object sender, EventArgs e)
       {
           this.KeyPreview = true;
           this.KeyDown += new KeyEventHandler(Form1_KeyDown);
       }

I believe you understand how to create a hotkey. Question are welcome and your queries are also welcome to please if you feel any kind of confusion then write it as comment. Suggestions are also welcome.

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger