Perform key actions or events in c#

Shortcuts:

keyup events allow user to use or press key to perform a particular task instead of using or clicking on button or on any control.

Example:

if we want that if user press ENTER KEY then login button get invoked instead of clicking login button through mouse.

use KEYUP event of that particualr control on which you want that on that control if user press ENTER then that task or event should performs:

I taken text box password's KEYUP event:

private void textpassword_KeyUp(object s,EventArgs e)
{
if (e.KeyCode == Keys.Enter)
                loginbutton.PerformClick();
}

in this code snippent when user enter password and then press ENTER Key then button login get perform task or login task.

here Keys in if block Enum type which have many Keys prop like Enter,NumPad1,NumPad0,NumPad2,NumPad3,NumPad4,NumPad5,Escape etc.....

here i taken On Enter Key

similerly if user want that if he/she press Escape key then application get Exit:

private void form_KeyUp(object s,EventArgs e)
{
if(e.KeyCode==Keys.Escape)
{
Application.Exit();
}
}

so there is many like that use and try

Thanking you
Ebook Download
View all
Learn
View all